FPDF add new font

I use the FPDF library for PHP to create reports, but now I need to use a different font (Verdana), which is not in the main fonts. I added the line:

$pdf->AddFont('Verdana','','verdana.php'); 

I copied the verdana.php and verdana.z files to the font directory. Everything works fine if I use the following instructions:

 $pdf->SetFont('Verdana','',6); 

But if I try to use the following command (to use bold):

 $pdf->SetFont('Verdana','B',6); 

I get an error message:

 FPDF error: Undefined font: verdana B 

I tried adding another font for Verdana Bold:

 $pdf->AddFont('Verdana-Bold','B','verdanab.php'); 

Of course, I put the verdanab.php and verdanab.z files in the font directory. But I get the same error. What am I missing or how to use Verdana fonts (normal and bold)?

Thanks in advance.

+8
php fonts fpdf
source share
4 answers

I read an interesting article about this. He should help you in what you are looking for.

Adding TrueType Fonts to FPDF Documents

Maybe something like this:

 $pdf->AddFont('Verdana','B','verdanab.php'); 
+8
source share

make sure you add the font directory at the top of the script before the request ('fpdf.php');

 define('FPDF_FONTPATH','./font/'); 

if you have already done this, simply remove the 'B' from the setFont () method. This is a quick fix, not a good practice.

 $pdf->SetFont('Verdana','',6); 

For more help, you can go through this. Adding new fonts and coding support.

+1
source share

Use this syntax:

$pdf->AddFont('Verdana','','verdanab.php');

instead of using:

$pdf->AddFont('Verdana','B','verdanab.php');

+1
source share

I solved this by defining a font for each style:

 $pdf->AddFont('Verdana','','verdana.php'); $pdf->AddFont('Verdanabold','','verdanabold.php'); 

Then use:

 $pdf->SetFont('Verdana','',6); // Regular style $pdf->SetFont('Verdanabold','',6); // Bold style 
0
source share

All Articles