野狼
野狼

技術宅大叔,喜歡貓、玩具、電玩、動漫、美劇、電影

Let TCPDF use Chinese fonts

foreword

During the coding process, when encountering the need to contain Chinese in the TCPDF output PDF file.

Program

You can use the built-in method of TCPDF to convert Chinese fonts for TCPDF use.

If you don't have a complete TCPDF file, download it from https://github.com/tecnickcom/tcpdf

How to handle

  1. full download tcpdf
  2. Open the tools directory under tcpdf, and put the authorized Chinese fonts into this directory
  3. Use the following command to output the converted font
php tcpdf_addfont.php -i 中文字體.ttf
  1. After the output is successful, Process successfully completed!
  2. Switch to the upper directory to the fonts directory, and you can see the fonts after the conversion is successful

How to use

No more notes on how to use TCDPF, here only notes on how to use Chinese

$pdf->SetFont('轉換後中文字型', '字型風格', 字型大小);
$pdf->Text(x 座標, y 座標, '要輸出的變數或是內容');

Remark

Using this method to convert fonts, some True Type fonts fail to be converted, so you have to replace other fonts to use.

Link to the original text

CC BY-NC-ND 2.0

Like my work?
Don't forget to support or like, so I know you are with me..

Loading...

Comment