FPDF add new font

Marco Muciño picture Marco Muciño · Jul 5, 2013 · Viewed 28.1k times · Source

I'm using the FPDF library for PHP to generate reports, but now I need to use another font (Verdana) that isn't in the core fonts. I added the line:

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

I copied the files verdana.php and verdana.z to the fonts directory. Every things works fine, if I use the next instructions:

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

But if I try to use the next instruction (to use the bold font):

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

I get the error:

FPDF error: Undefined font: verdana B

I tried adding another font for the Verdana Bold:

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

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

Thanks in advance.

Answer

SeanWM picture SeanWM · Jul 5, 2013

I read through an interesting article on this. It should help you with what you're looking for.

Adding TrueType Fonts to FPDF Documents

Maybe something like this:

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