How to implement custom fonts in TCPDF

In TCPDF, there are only a few fonts to choose from, to create pdf files. I want to set Tahoma as my pdf font. How can I include Tahoma in TCPDF??


The latest TCPDF version automatically convert fonts into TCPDF format using the addTTFfont() method. For example:

// convert TTF font to TCPDF format and store it on the fonts folder
$fontname = TCPDF_FONTS::addTTFfont('/path-to-font/FreeSerifItalic.ttf', 'TrueTypeUnicode', '', 96);

// use the font
$pdf->SetFont($fontname, '', 14, '', false);

For further information and examples, please check the TCPDF Fonts documentation page.

NOTE: Once the font has been converted, TCPDF no longer requires the TTF file or the above call to addTTFfont()!


I have discovered a very good tool online. The only thing you need to do is to upload your .ttf file and then download the files and copy then into the /fonts folder.

https://www.xml-convert.com/en/convert-tff-font-to-afm-pfa-fpdf-tcpdf


The addTTFfont method is not available on TCPDF main class so following worked for me.

// convert TTF font to TCPDF format and store it on the fonts folder
$fontname = TCPDF_FONTS::addTTFfont('pathto/arial.ttf', 'TrueTypeUnicode', '', 96);

// use the font
$pdf->SetFont($fontname, '', 14, '', false);

Hope this helps!


the below lines will generate 3 files in ur fonts folder 1.rotisserifi56.php 2.rotisserifi56.ctg 3.rotisserifi56.rar

    use this to generate the required php and other files
$fontname = $this->pdf->addTTFfont('D:/wamp/www/projectname/sites/all/modules/civicrm/packages/tcpdf/fonts/Rotis Serif Italic 56.ttf', 'TrueTypeUnicode', '', 32);

    // use the font
    $this->pdf->SetFont($fontname, '', 14, '', false);

Now,

use the fonts like this:

 $this->pdf->AddFont('rotisserifi56', '', 'rotisserifi56.php');
$this->pdf->SetFont('rotisserifi56');

--hope this helps some one :)


First create .php ,.afm,.z from http://www.xml-convert.com/en/convert-tff-font-to-afm-pfa-fpdf-tcpdf and move all three in same directory containing .ttf file. then Use This :

$pdf->AddFont(path-to/universe.ttf','',path-to/universe.php');
$pdf->SetFont(path-to/universe.ttf','',10);