PHP HTML2PDF.js Example to Insert Custom Google Fonts inside PDF Document in Browser Using HTML5 & Javascript

  • Post author:
  • Post category:PHP
  • Post comments:0 Comments





Creating new Font

To create new font, you should use this tutorial from TCPDF:

Adding new font

To use this new font, you must add it to Html2Pdf, by using the following method:

The parameters are:

Parameter Default Description
$family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
$style Font style. Possible values are (case insensitive):

  • empty string: regular (default)
  • B: bold
  • I: italic
  • BI or IB: bold italic
$file The font definition file. By default, the name is built from the family and style, in lower case with no spaces.

If you want to add font for normal and for bold style, you must call the addFont method twice, one for each font file.

WARNING: In 4em parameter constructor of Html2pdf, you must specify whether you use a Unicode font (true) or an old font (false).

Using new font

You have just to se the new font family name in your css.

Setting the default font

You can set the default font to use with the following method:

Leave a Reply