How to implement custom fonts in TCPDF

Alfred picture Alfred · Mar 10, 2011 · Viewed 91.8k times · Source

In TCPDF, there are only a few fonts to choose from, to create pdf files. I want to set Tahoma as my pdf font. How can I include Tahoma in TCPDF??

Answer

Nicola Asuni picture Nicola Asuni · Oct 2, 2011

The latest TCPDF version automatically convert fonts into TCPDF format using the addTTFfont() method. For example:

// convert TTF font to TCPDF format and store it on the fonts folder
$fontname = TCPDF_FONTS::addTTFfont('/path-to-font/FreeSerifItalic.ttf', 'TrueTypeUnicode', '', 96);

// use the font
$pdf->SetFont($fontname, '', 14, '', false);

For further information and examples, please check the TCPDF Fonts documentation page.

NOTE: Once the font has been converted, TCPDF no longer requires the TTF file or the above call to addTTFfont()!