问题
I have to generate a PDF from php page contains html which includes unicode fonts (Telugu). Its showing perfectly when I print html code and while rendering to PDF using TCPDF, the unicode characters are distorting of letter formations.
I have copied the telugu font from google translators and added a telugu font into tcpdf lib.
$message = '<h2 align="center">ధన్యవాదములు -- శుభోదయం</h2>';
$fontname = $pdf->addTTFfont('E:\xampp\htdocs\ncs\svdn\flowers\tcpdf\fonts\mandali-regular.ttf', 'TrueTypeUnicode');
$pdf->SetFont($fontname, "",30, false);
$pdf->writeHTML($message, true, 0, true, 0);
$pdf->Output("Test.pdf", 'I');
The output in html is like below. And the same has to be printed in PDF too.
ధన్యవాదములు -- శుభోదయం
But in current issue, the above consonants are disjointed:
回答1:
TCPDF doesn't support the OpenType layout features needed for Indic scripts to work.
mPDF supports several indic scripts - including Telugu specifically - however, so if you're not too far along in your project to switch, that would be my recommendation.
This code should work for instance (though I have not tested it) after installing mPDF with composer:
include 'vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf();
//I'm being a little lazy here and letting mPDF select the appropriate
//appropriate font.
$mpdf->autoScriptToLang = true;
$mpdf->baseScript = 1; // Use values in classes/ucdn.php 1 = LATIN
$mpdf->autoLangToFont = true;
$mpdf->WriteHTML('<h2 style="text-align: center;">'.
'ధన్యవాదములు -- శుభోదయం</h2>');
$mpdf->Output('test_mpdf_lang.pdf');
来源:https://stackoverflow.com/questions/58776485/is-there-any-configurations-required-to-show-telugu-unicode-fonts-in-tcpdf