Monday, February 13, 2012

TCPDF - Chinese encoding UTF-08 fonts

At first, I was looking for FPDF instead of TCPDF, since FPDF seems light weighter than TCPDF, and people told their experience that TCPDF seems taking a bit longer processing time.

However, since my project requires to show the Chinese Characters, I found that I don't feel FPDF has sufficient support on UTF-08 encoding of Chinese Characters.

Then, I tried TCPDF and found that they give many examples on their webpage and show their product features. This helps me a lot to understand how it works and how to code.

The Chinese character encoding is pretty easy with the setting of UTF-08 and choosing the appropriate fonts, 'stsongstdlight' or 'kozminproregular'.

e.g.
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

For displaying traditional Chinese characters, I recommend to use font, 'kozminproregular'; 'stsongstdlight' is better for displaying simplified-Chinese characters.

e.g.
$pdf->SetFont('kozminproregular', '', 10);

Updated: 2013-05-02
Lastly, I found 'cid0cs' and 'cid0ct' work better.

1 comment: