10

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.

Marco Muciño
  • 620
  • 2
  • 9
  • 19

5 Answers5

8

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');
SeanWM
  • 16,789
  • 7
  • 51
  • 83
2

make sure you have added the font directory at the top of the script before require('fpdf.php');

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

if you have already done that, then just remove 'B' from the setFont() method. Its a quick fix and not a good practice.

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

For more help you can go through this Adding new fonts and encoding support

silk_route11
  • 324
  • 3
  • 17
2

Use this syntax:

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

instead of using:

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

fkoessler
  • 6,932
  • 11
  • 60
  • 92
Ashutosh Srivastava
  • 103
  • 1
  • 1
  • 10
1

Standart Font Families:

Courier (fixed-width)
Helvetica or Arial (synonymous; sans serif)
Times (serif)
Symbol (symbolic)
ZapfDingbats (symbolic)

Here you can create your own .php file for Fpdf:

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

devugur
  • 1,339
  • 1
  • 19
  • 25
0

I solved it 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
Stefan Vogt
  • 1,513
  • 2
  • 10
  • 16