PHP: TCPDF Font style Change(Adding external fonts)

TCPDF is a PDF library for generating PDF for given content. The Library is open source available on https://tcpdf.org/. We can download that library to create PDF for our need. This article will demonstrate how to change default font style of TCPDF library with our custom TTF font file.

Below is the essential steps to follow to change the font style.

1. Get TCPDF Library from Online
  https://github.com/tecnickcom/tcpdf
 
2. Set Library in your local server
  http://localhost/tcpdf/
 
3. Example PDF generators
  http://localhost/tcpdf/examples/

4. Get new font file (TTF format) from online
  http://www.webpagepublicity.com/free-fonts-x.html
 
5. Generate Font library for the new font file. 

 php tcpdf/tools/tcpdf_addfont.php -i tcpdf/fonts/NEW_FONT.ttf   

  It will generate new 2 Zipped folders(NEW_FONT.z and NEW_FONT.ctg.z) and one PHP file(NEW_FONT.php) of Font style configuration.
 
6. Set new font format to PDF file generator 

$pdf->SetFont(NEW_FONT, NULL, 8); 

 

Category: