It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.

NOTE: The following information is valid only fot the old TCPDF library. The new tc-lib-pdf library uses the new tc-lib-pdf-font library that is able to convert fonts on the fly.

TCPDF supports TrueTypeUnicode (UTF-8 Unicode), OpenTypeUnicode, TrueType, OpenType, Type1, CID-0 and Core (standard) fonts.
There are two ways to use a new font: embedding it in the PDF (with or without subsetting) or not. When a font is not embedded, it is searched in the system. The advantage is that the PDF file is lighter; on the other hand, if it is not available, a substitution font is used. So it is preferable to ensure that the needed font is installed on the client systems. If the file is to be viewed by a large audience, it is recommended to embed.

TCPDF support font subsetting to reduce the size of documents using large unicode font files. If you embed the whole font in the PDF, the person on the other end can make changes to it even if he didn't have your font. If you subset the font, file size of the PDF will be smaller but the person who receives your PDF would need to have your same font in order to make changes to your PDF. The option for enabling/disabling the font subsetting are explained on the source code documentation for methods SetFont() and AddFont().

The fonts that could be not embedded are only the standard core fonts and CID-0 fonts.

The PDF Core (standard) fonts are:
  • courier : Courier
  • courierB : Courier Bold
  • courierBI : Courier Bold Italic
  • courierI : Courier Italic
  • helvetica : Helvetica
  • helveticaB : Helvetica Bold
  • helveticaBI : Helvetica Bold Italic
  • helveticaI : Helvetica Italic
  • symbol : Symbol
  • times : Times New Roman
  • timesB : Times New Roman Bold
  • timesBI : Times New Roman Bold Italic
  • timesI : Times New Roman Italic
  • zapfdingbats : Zapf Dingbats

Convert a font for TCPDF

Using the addTTFfont() method you can directly create a TCPDF font starting from a TrueType, OpenType or Type1 font.
NOTE: The ‘fonts’ folder must be writeable by the webserver.

For example:

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

Check the source code documentation of addTTFfont() for further information.

Set the Font

On the configuration file (config/tcpdf_config.php) set the K_PATH_FONTS constant to the TCPDF fonts path.
On the fourth parameter of the TCPDF class constructor you have to specify if you are using Unicode fonts (true) or old fonts (false).

To set the font in your script you just need to call the SetFont() method. It is mandatory to call this method at least once before printing text or the resulting document would not be valid. The method can be called before the first page is created and the font is retained from page to page:
SetFont(string family[,string style[,string size]])
  • family : Family font. It can be either a font name or one of the standard families (case insensitive):
    • Courier (fixed-width)
    • Helvetica or Arial (synonymous; sans serif)
    • Times (serif)
    • Symbol (symbolic)
    • ZapfDingbats (symbolic)
    It is also possible to pass an empty string. In that case, the current family is retained.
  • style : Font style. Possible values are (case insensitive):
    • empty string: regular
    • B: bold
    • I: italic
    • U: underline
    or any combination. The default value is regular.
  • size : Font size in points. The default value is the current size. If no size has been specified since the beginning of the document, the value taken is 12.
  • fontfile : The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
  • subset : If true embedd only a subset of the font (stores only the information related to the used characters); if false embedd full font; if ‘default’ uses the default value set using setFontSubsetting(). This option is valid only for TrueTypeUnicode fonts. If you want to enable users to change the document, set this parameter to false. If you subset the font, the person who receives your PDF would need to have your same font in order to make changes to your PDF. The file size of the PDF would also be smaller because you are embedding only part of a font.
$pdf->SetFont(‘times’, ‘BI’, 20, “, ‘false’);

? 2004-2019 – Nicola Asuni - - All rights reserved.
about - disclaimer - privacy