Leorah Sumarong
Leorah Sumarong

Reputation: 127

Adding new fonts in TCPDF

Does anybody can help me how to install or add new font in TCPDF. I already got the .z,php and .ttf file in my font. And how to display or use the font.. I stored the given file into fonts folder.
I used CodeIgniter.

Upvotes: 1

Views: 7213

Answers (4)

atm-florianm
atm-florianm

Reputation: 11

If you don't want to rely upon a third party website for converting the fonts (be it because you are reluctant to run executable code generated from an untrusted third party or simply because these sites are no longer there, like xml-convert.com), you can use TCPDF's script TCPDF/tools/tcpdf_addfont.php.

php TCPDF/tools/tcpdf_addfont.php --help

For each TTF file, it will generate a .z, a .php and a .ctg.z file, which you will need to put in your TCPDF fonts directory.

Then you can use it in the SetFont() method. Remember you may need to generate files for all variants you plan to use (regular, italic, bold, bold italic etc.).

Upvotes: 0

Kamlesh
Kamlesh

Reputation: 6135

TCPDF: How to add new custom font in tcpdf

  1. Download required font's ttf file
  2. Open http://www.fpdf.org/makefont website in the browser and upload the ttf font on this website
  3. Download two files customfontname.php and customfontname.z
  4. Copy these two files into /yourproject/vendor/tecnickcom/tcpdf/fonts/ folder
  5. include / set the font in your script before tcpdf html code $pdf->SetFont('customfontname', '', 12);

Upvotes: -1

X A
X A

Reputation: 837

Have you checked this?

https://tcpdf.org/docs/fonts/

something like this should work I think.

$fontname = $pdf->addTTFfont('/path-to-font/DejaVuSans.ttf', 'TrueTypeUnicode', '', 32);

Upvotes: 1

Bharat
Bharat

Reputation: 216

You can do the below thing. If you have .ttf file for the new font then convert that font to .php and .z files using below link http://www.xml-convert.com/en/convert-tff-font-to-afm-pfa-fpdf-tcpdf

Once you converted the fonts download the .php and .z file and upload it into tcpdf's fonts folder. TCPDF will consider your filename as your fontname so make sure you have correct file names.

Once files are uploaded you can directly use setfont function of tcpdf.

Upvotes: 4

Related Questions