Is there any configurations required to show telugu unicode fonts in tcpdf?

会有一股神秘感。 提交于 2021-02-11 06:31:26

问题


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:

picture showing disjointed consonants


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!