Reputation: 620
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.
Upvotes: 10
Views: 33962
Reputation: 1499
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:
Upvotes: 1
Reputation: 1533
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
Upvotes: 0
Reputation: 103
Use this syntax:
$pdf->AddFont('Verdana','','verdanab.php');
instead of using:
$pdf->AddFont('Verdana','B','verdanab.php');
Upvotes: 2
Reputation: 344
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
Upvotes: 3
Reputation: 16989
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');
Upvotes: 8