Creating PDFs using TCPDF that supports all languages especially CJK

蓝咒 提交于 2019-12-17 18:43:40

问题


Can someone put together a clear and concise example of how you can create a PDF using TCPDF that will support text strings from any language?

It appears there is not a single font that will support all languages. I'm guessing the font would be too large?

I assume the correct way would be to detect the language of the string and dynamically set the font type to a compatible font. If this is the case then it gets very complex in detecting the language for each string.

Most languages are supported if you use the "freeserif" font. However it does not support CJK fonts. I've tried many fonts (kozminproregular, cid0jp, cid0kr, cid0jp, stsongstdlight) to get support for Chinese, Japanse, and Korean, but none of them seem to support all three languages.


回答1:


This worked out perfectly for me. Thank you!

To make sure, the generated PDF file will not get to big, use FontSubsetting - I have a 10 page PDF generated with only a few Lines of chinese (Names on Diplomas)

$pdf->setFontSubsetting(true); => PDF File slightly bigger 925kb vs 755kb without the chinese names if you use $pdf->setFontSubsetting(false); => PDF File size as about 17.5 MB ...




回答2:


Managed this problem by making my own font from arial ms unicode with these steps:

In a temporal script put and execute this
1. put a copy of ARIALUNI.ttf in fonts folder under tcpdf installation (i've taken my copy from windows\fonts folder.
2. make a temporary script in examples folder of tcpdf and execute it with this line:
$fontname = $pdf->addTTFfont('../fonts/ARIALUNI.ttf', 'TrueTypeUnicode', '', 32);
3. set the new font in your pdf generator script:
$pdf->SetFont('arialuni', '', 20);

Now the pdf should be showing correctly CJK characters.
Hope this helps so many people.




回答3:


I just tried Etiennez0r's solution, and it didn't work for me. Needed to make a minor modification as below:

$fontname = TCPDF_FONTS::addTTFfont('../fonts/ARIALUNI.TTF', 'TrueTypeUnicode', '', 96);



回答4:


I setting:

$fontname = TCPDF_FONTS::addTTFfont(FCPATH . 'TCPDF/fonts/ARIALUNI.ttf', 'TrueTypeUnicode', '', 32);

....... // set font

$pdf->SetFont('dejavusans', '', 14);
$pdf->SetFont('cid0cs', '', 14);

Export Japanese is working well



来源:https://stackoverflow.com/questions/9426983/creating-pdfs-using-tcpdf-that-supports-all-languages-especially-cjk

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