How do you add custom fonts in TCPDF?

I figured out my issue, I was almost there.

Here is a step by step:

First convert your font using the tcpdf_addfont.php tool font in the TCPDF tools folder:

php/tcpdf/tools/tcpdf_addfont.php -i php/font/rumpelstiltskin-webfont.ttf

This will generate the required files and put them in the TCPDF fonts folder. Check the fonts folder and copy the name of the font, in my case it was rumpelstiltskinwebfont.

In your code set the font using the font file’s name and write a line of text:

$pdf->SetFont('rumpelstiltskinwebfont', '', 14, '', false);
$pdf->Write(0, 'Fill text', '', 0, '', true, 0, false, false, 0);

That’s it. Hope this helps someone. 🙂

Leave a Comment