Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FPDF add new font

Tags:

php

fonts

fpdf

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.

like image 398
Marco Muciño Avatar asked Jul 05 '13 03:07

Marco Muciño


People also ask

How do I add fonts to Fpdf?

php'); $pdf = new FPDF(); $pdf->AddFont('CevicheOne','','CevicheOne-Regular. php'); $pdf->AddPage(); $pdf->SetFont('CevicheOne','',35); $pdf->Write(10,'Enjoy new fonts with FPDF!'

How do I add fonts to info plist?

To do this, add the key "Fonts provided by application" to Info. plist (the raw key name is UIAppFonts ). Xcode creates an array value for the key; add the name of the font file as an item of the array. Be sure to include the file extension as part of the name.

How do I add custom fonts to swift 5?

Adding Custom Fonts to the projectDrag and Drop your font files in the new folder and choose the checkboxes for Copy items if needed and Add to targets. Then press Finish. Press the arrow next to Fonts provided by application and add the font file names.


3 Answers

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/

like image 130
devugur Avatar answered Oct 19 '22 17:10

devugur


Use this syntax:

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

instead of using:

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

like image 33
Ashutosh Srivastava Avatar answered Oct 19 '22 16:10

Ashutosh Srivastava


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

like image 20
silk_route11 Avatar answered Oct 19 '22 18:10

silk_route11