How to add a custom font to TCPDF?

Asked

Viewed 156 times

2

I’m using TCPDF to generate (obvious) Pdfs and need to add a custom source.

I took a look at documentation and there it says that has 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()

That method addTTFfont is somewhere else?

How to add custom fonts in TCPDF?

1 answer

4


The first note of the documentation link you posted:

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.

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 the method can be used normally TCPDF::SetFont();


Addendum:

Although I consider TCPDF to be the most complete library, it is quite confusing in some respects and in part for its documentation...

  • Yeah. The method I saw here was \TCPDF_FONTS::addTTFfont, in a reply from the SOEN, kkkkk

Browser other questions tagged

You are not signed in. Login or sign up in order to post.