How to add a custom font in TCPDF?

2

I'm using TCPDF to generate PDFs (obvious) and need to add a custom font.

I took a look at documentation and it says there is a method called addTTFfont .

The problem is, when I try to call, an error is returned, saying that the method does not exist:

  

Call to undefined method TCPDF :: addTTFfont ()

Is this addTTFfont method elsewhere?

How to add custom fonts in TCPDF ?

    
asked by anonymous 31.10.2018 / 13:20

1 answer

4

The first note of the documentation link you posted:

  

NOTE: The following information is valid only from 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.

The current library method is TCPDF::AddFont()

/**
 * Imports a TrueType, Type1, core, or CID0 font and makes it available.
 * It is necessary to generate a font definition file first (read /fonts/utils/README.TXT).
 * The definition file (and the font file itself when embedding) must be present either in the current directory or in the one indicated by K_PATH_FONTS if the constant is defined. If it could not be found, the error "Could not include font definition file" is generated.
 * @param $family (string) Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
 * @param $style (string) Font style. Possible values are (case insensitive):<ul><li>empty string: regular (default)</li><li>B: bold</li><li>I: italic</li><li>BI or IB: bold italic</li></ul>
 * @param $fontfile (string) The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
 * @return array containing the font data, or false in case of error.
 * @param $subset (mixed) 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.
 * @public
 * @since 1.5
 * @see SetFont(), setFontSubsetting()
 */
public function AddFont($family, $style='', $fontfile='', $subset='default');

Then you can usually use the TCPDF::SetFont();

Addendum :

Although I consider TCPDF the most complete library, it is quite confusing in some respects and partly because of its documentation ...

    
31.10.2018 / 13:37