Programmatically Add TCPDF Font

Cartoon image of a programmer in glasses at a desk looking at a screen.

If youโ€™re not a developer and don’t know one or won’t hire one, you might want to stop reading here. ๐Ÿ˜œ

The filter โ€œpdfink_filter_tcpdf_font_nameโ€ adds more granular control of font use during TCPDF manipulations. The font will be added to TCPDF using AddFont().

function pdfink_filter_tcpdf_font_name( $font_family, $tcpdf, $settings ) {
    /**
     * addTTFfont() parameters:
     * 
     * $fontfile (string) Font file (full path).
     * $fonttype (string) Font type. Leave empty for autodetect mode. Valid values are: TrueTypeUnicode, TrueType, Type1, CID0JP = CID-0 Japanese, CID0KR = CID-0 Korean, CID0CS = CID-0 Chinese Simplified, CID0CT = CID-0 Chinese Traditional.
     * $enc (string) Name of the encoding table to use. Leave empty for default mode. Omit this parameter for TrueType Unicode and symbolic fonts like Symbol or ZapfDingBats.
     * $flags (int) Unsigned 32-bit integer containing flags specifying various characteristics of the font (PDF32000:2008 โ€“ 9.8.2 Font Descriptor Flags): +1 for fixed font; +4 for symbol or +32 for non-symbol; +64 for italic. Fixed and Italic mode are generally autodetected so you have to set it to 32 = non-symbolic font (default) or 4 = symbolic font.
     * $outpath (string) Output path for generated font files (must be writeable by the web server). Leave empty for default font folder.
     * $platid (int) Platform ID for CMAP table to extract (when building a Unicode font for Windows this value should be 3, for Macintosh should be 1).
     * $encid (int) Encoding ID for CMAP table to extract (when building a Unicode font for Windows this value should be 1, for Macintosh should be 0). When Platform ID is 3, legal values for Encoding ID are: 0=Symbol, 1=Unicode, 2=ShiftJIS, 3=PRC, 4=Big5, 5=Wansung, 6=Johab, 7=Reserved, 8=Reserved, 9=Reserved, 10=UCS-4.
     * $addcbbox (boolean) If true includes the character bounding box information on the php font file.
     * $link (boolean) If true link to system font instead of copying the font data (not transportable) โ€“ Note: do not work with Type1 fonts.
     */
    $font = \LittlePackage\pdfInk\PDF\lib\tcpdf\tecnick\tcpdf\includes\TCPDF_FONTS::addTTFfont( $font_file, $font_type, $enc, $flags, $outpath, $platid, $encid, $addcbbox, $linkbox );
    if ( $font ) {
        return $font;
    } 
    return $font_family;
}

The $font value returned will be run in $tcpdf->SetFont().

See documentation on the TCPDF AddFont() method.

To top