14

How can I add the Gotham-book font to fpdf. Most explanations are unclear and very difficult to understand. I need an example. Please can someone assist?

Janinekey
  • 431
  • 1
  • 4
  • 8

3 Answers3

25

Nevermind Got my answer

Go to http://www.fpdf.org/makefont/

Convert your .ttf file

Download the .php and the .z file

Add these files to the following folder: fpdf/font
(This is the default folder structure that you need to download in order for your fpdf to work)

This is the code I have used in my file:

$fpdf->AddFont('Gotham','','Gotham-Book.php');
    $fpdf->SetFont('Gotham','',11); 
Jan Slabon
  • 4,736
  • 2
  • 14
  • 29
Janinekey
  • 431
  • 1
  • 4
  • 8
  • 1
    You can alter that path with `define('FPDF_FONTPATH', "yourPath");` but still you have to add all font definition files there... – jave.web Mar 11 '20 at 00:17
10

I was also stuck with this error, @Janinekey's answer is right but I didn't find how to add variants of a font. This article explains this process really well too.

I will explain the whole process in steps.

Step 1. Download all the variant's of your font (Regular, Bold, Italic, Bold-Italic)

Step 2. Convert all the fonts to font-name.php and font-name.z from this link

Step 3. Copy all *.php and *.z files in fonts/ folder which is in root directory of fpdf.php. [You can rename *.php files, but don't rename *.z once you converted them from ttf].

Step 4. Use this code to import the font into your pdf:

//Importing Font and it's variations
$fpdf->AddFont('Gotham','','Gotham-Book.php'); //Regular
$fpdf->AddFont('Gotham','B','Gotham-Book-bold.php'); //Bold
$fpdf->AddFont('Gotham','I','Gotham-Book-italic.php'); //Italic
$fpdf->AddFont('Gotham','BI','Gotham-Book-bold-italic.php'); //Bold_Italic

//Now use it as normal font
$fpdf->SetFont('Gotham','B',11);

PS: Font name will be same for different variants. So, make sure you don't change it, otherwise you will treat it as another font completely.

Sumit Badsara
  • 769
  • 9
  • 23
0

To set the font you can try this snippet:

pdf = PDF()
pdf.add_font('Roboto','','path_of_the_.ttf_file',uni=True)

and then

self.set_font('Roboto', '', 8)   
mohain
  • 1