PHP 7 HTML2PDF.js Script to Insert Custom TTF Fonts to PDF Document in Browser Using HTML5 & Javascript

 

 

I have managed to add 1 custom font to my setup using the following method.

First convert the .ttf file to 3 separate files (.php .z and .ufm) using the following font converter Place the 3 files that are generated by this system into the fonts folder in TCPDF.

Now you can set the default font for your PDF using the following command

This was fairly simple to get working, I am having issues using 2 seperate fonts though via this method. I’ll figure it out though

 

To expand on the selected answer (by o11y_75) when you convert your fonts, you need to use a specific name to include also the bold and italic variants. That way, you only add one font definition like this

When you convert the fonts, name them, for example, like these:

notice that behind the original name, you add b, i and bi on each case. I have found no documentation on this issue, but I followed the nomenclature found on the fonts that already came with TCPDF and it worked.

 

To expand on the selected answer (by o11y_75) when you convert your fonts, you need to use a specific name to include also the bold and italic variants. That way, you only add one font definition like this

When you convert the fonts, name them, for example, like these:

notice that behind the original name, you add b, i and bi on each case. I have found no documentation on this issue, but I followed the nomenclature found on the fonts that already came with TCPDF and it worked.

 

Leave a Reply