Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating PDFs using TCPDF that supports all languages especially CJK

Tags:

php

cjk

tcpdf

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.

like image 560
Matt Avatar asked Feb 24 '12 07:02

Matt


1 Answers

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 ...

like image 110
Christian K. Avatar answered Sep 18 '22 14:09

Christian K.