TCPDF display chinese characters

There is a way to embed a TTF that can display Chinese characters.

Developer can use a font that:

  • Can display Chinese
  • Can be embedded to PDF

The fonts Droid Sans Fallback, which is free.

  1. copy the font to ./lib/TCPDF/fonts/DroidSansFallback.ttf
  2. use the below sample code in using the Droid Sans Fallback to output chinese characters
TCPDF_FONTS::addTTFfont('./lib/TCPDF/fonts/DroidSansFallback.ttf', 'TrueTypeUnicode', '', 32);
$pdf->SetFont('DroidSansFallback', '', 20);
$html = '中文字';
$pdf->SetFont('DroidSansFallback', '', 20);
$pdf->writeHTML($html, true, false, false, false, '');
$pdf->SetFont('DroidSansFallback', '', 10);
$pdf->writeHTML($html, true, false, false, false, '');
$pdf->SetFont('DroidSansFallback', '', 8);
$pdf->writeHTML($html, true, false, false, false, '');
This entry was posted in Development and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *