- TCPDF 6.0.020
- PHP 5.3.8
- Windows 7
The problem:If you follow this post that said: using cid0cs or cid0ct to display Chinese, it can display the character correctly, only to the extend that user installed a correct font package. However, chances are other users who didn't install that package cannot view that PDF since there are several packages and versions of PDF viewer (mainly Adobe). And even worse: even if user installed certain CJK font package, the PDF still not displayed correctly (show empty page).
And according to the official TCPDF documentation about font:
The fonts that could be not embedded are only the standard core fonts and CID-0 fonts.
The solution:Again, thanks to the post above (in simplified Chinese), now developer can use a font that:
- Can display Chinese
- Can be embedded to PDF
The font is called: Droid Sans Fallback, which is free. You can download it from MediaFire below:
All you need to do are:
- To rename it from Droid Sans Fallback.ttf to DroidSansFallback.ttf (Remove the space only)
- Put the file under tcpdf/fonts/ (in this case the final destination will be tcpdf/fonts/DroidSansFallback.ttf).
- In your PDF generation code, enter:
- $pdf->addTTFfont('fonts/DroidSansFallback.ttf'); Updated: Mind the path here, please make sure you have correct path to the ttf file.
- $pdf->SetFont('DroidSansFallback', '', 12, '', false);
To test, you use the examples file (better use examples/example_038.php) and edit the file to test.
Points to note:
- Make your tcpdf/fonts/ directory writable, as you call the addTTFfont() function, 3 files will be created inside that directory. If the system cannot get access from the outside, it won't work.
- The 3 files are:
Hope it helps someone.