DEV Community

loading...

How to Add Fonts to TCPDF in Your Project

ekastrya profile image ekastrya ・1 min read

(Versi Bahasa Indonesia: https://medium.com/@ekastrya/cara-menambah-font-untuk-tcpdf-17af6808b76)

Earlier today, I was assigned a simple task to add two custom fonts for a client's project. It took me 15 minutes on Stack Overflow to find a fast way to do this. Found it and here are the steps:

  1. Install / download / require the tcpdf library into your project.
  2. Open the library folder (for example mine was: ./vendor/tecnickcom/tcpdf).
  3. Notice and enter to the tools folder.
  4. Copy the TTF file(s) into this tools folder.
  5. Run this command from the terminal (still from the tools folder): $ php tcpdf_addfont -i BOOKOS.TTF (Replace BOOKOS.TTF with your own fonts)
  6. Repeat step (5) for each fonts desired.

Coding time..
To change between fonts from your php code, use the following scripts.

$pdf->SetFont($font_family = ‘bookos’, $variant = ‘’, $fontsize = 11);

(Versi Bahasa Indonesia: https://medium.com/@ekastrya/cara-menambah-font-untuk-tcpdf-17af6808b76)

Discussion

pic
Editor guide