ตัวที่ใช้ในการแปลง ก็ติดมากับ source เวลาเรา download tcpdf/html2pdf มา (เรารู้แล้วว่า html2pdf ใช้ tcpdf เป็น core หลัก จากบทความนี้)

ส่วนบทความนี้เรียกว่าเอา readme ที่เขาให้มาแล้วนั้น นำมาอธิบายขั้นตอนให้กระชับมากขึ้นแทนละกันครับ

TCPDF supports TrueTypeUnicode (UTF-8 Unicode), OpenTypeUnicode, TrueType, OpenType, Type1, CID-0 and Core (standard) fonts.

  • font ภาษาไทยพวก .ttf จะอยู่ในตระกูล TrueTypeUnicode

Setting up a font for usage with TCPDF steps:

1. Convert all font filenames to lowercase and rename:

* [basic-font-name-in-lowercase].ttf for regular fontTCPDF Fonts (ttf2ufm)
* [basic-font-name-in-lowercase]b.ttf for bold variation
* [basic-font-name-in-lowercase]i.ttf for oblique variation
* [basic-font-name-in-lowercase]bi.ttf for bold oblique variation

  • เปลี่ยนชื่อ font กรณีตัวหนาเอียง บางทีเวลาเรา copy จาก c:\windows\fonts จะลงท้ายด้วย z.ttf ดังนั้นต้องเปลี่ยนชื่อก่อนด้วย
  • หากไฟล์มีไม่ครบก็ไม่เป็นไร เพียงแต่เวลาเราต้องการใช้ font ประเภทนั้นๆ หากไม่มีก็จะกลายเป็น type regular font ธรรมดาแทน

2. Generate the font’s metrics file.

* For Type1 font files this first step is not necessary because the AFM file is usually shipped with the font. In case you have only a metric file in PFM format, use the pfm2afm utility (fonts/utils/pfm2afm) to get the AFM file. If you own a Type1 font in ASCII format (.pfa), you can convert it to binary format with Type 1 utilities.
* For TrueTypeUnicode or TrueType font files, use the the provided ttf2ufm utility (fonts/utils/ttf2ufm):

* For OpenTypeUnicode or OpenType font files, use the the provided ttf2ufm utility (fonts/utils/ttf2ufm):

$ ttf2ufm -a -F myfont.otf

3. Run makefont.php script.

* For TrueTypeUnicode:

  • ไฟล์ .ufm นั้นได้มาจากขั้นตอนที่ 2 ของคำสั่ง ttf2ufm, myfont คือชื่อ font ที่เราต้องการ เช่น angsau ( AngsanaUPC ) เป็นต้น
  • เราใช้ command นี้ โดยอาจเิพิ่ม argument ตัวที่ 3 เป็น cp874 ดังนี้ php -q makefont.php myfont.ttf myfont.ufm cp874
  • เมื่อรัน php -q makefont.php เรียบร้อยแล้ว จะได้ไฟล์  3 ไฟล์ myfont.php, myfont.ctg.z, myfont.z แล้วนำไปวางที่ folder fonts ของ tcpdf / html2pdf

* For OpenTypeUnicode:

$ php -q makefont.php myfont.otf myfont.ufm

* For TrueType:

$ php -q makefont.php myfont.ttf myfont.afm

* For OpenType:

$ php -q makefont.php myfont.otf myfont.afm

* For Type1:

$ php -q makefont.php myfont.pfb myfont.afm

You may also specify additional parameters:

MakeFont(string $fontfile, string $fmfile [, boolean $embedded [, $enc=”cp1252″ [, $patch=array()]]])

* $fontfile : Path to the .ttf or .pfb file.
* $fmfile : Path to the .afm file for Type1 and TrueType or .ufm for TrueTypeUnicode.
* $embedded : Set to false to not embed the font, true otherwise (default).
* $enc : Name of the encoding table to use. Default value: cp1252. Omit this parameter for TrueType Unicode,

OpenType Unicode and symbolic fonts like Symbol or ZapfDingBats. The encoding defines the association between a code (from 0 to 255) and a character. The first 128 are fixed and correspond to ASCII. The encodings are stored in .map files.

Those available are:
o cp1250 (Central Europe)
o cp1251 (Cyrillic)
o cp1252 (Western Europe)
o cp1253 (Greek)
o cp1254 (Turkish)
o cp1255 (Hebrew)
o cp1257 (Baltic)
o cp1258 (Vietnamese)
o cp874 (Thai)
o iso-8859-1 (Western Europe)
o iso-8859-2 (Central Europe)
o iso-8859-4 (Baltic)
o iso-8859-5 (Cyrillic)
o iso-8859-7 (Greek)
o iso-8859-9 (Turkish)
o iso-8859-11 (Thai)
o iso-8859-15 (Western Europe)
o iso-8859-16 (Central Europe)
o koi8-r (Russian)
o koi8-u (Ukrainian)

Recent วิธีการแปลง font thai ttf ใช้งานกับ html2pdf หรือ tcpdf Search Terms:

  • - tcpdf ภาษาไทย (16)
  • - html2pdf ภาษาไทย (24)
วิธีการแปลง font thai ttf ใช้งานกับ html2pdf หรือ tcpdf