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.
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');
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
Use this syntax:
$pdf->AddFont('Verdana','','verdanab.php');
instead of using:
$pdf->AddFont('Verdana','B','verdanab.php');
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:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.