开发者

How to embed fonts with FPDF and mPDF

I'm trying to embed Helvetica Neue into my PDF, but all of the reso开发者_运维技巧urces I find online are overly complicated and filled with what I think is unneeded information.

Can anyone point me to a step by step tutorial of how to include fonts in FPDF?

Thanks in advance.


It's not too hard.

Suppose we want to add the Rockford font.

First, we need to use ttf2pt1 (or some equivalent program) to generate the AFM file for Rockford. Run the following command in a shell.

ttf2pt1 Rockford

The command will create Rockford.afm in the current shell directory.

Change your shell to the the makefont directory in the fpdf installation directory

cd /<...>/fpdf/font/makefont

Execute an interactive php shell

php -a

Run the following commands in the interactive PHP shell.

php > require("makefont.php");
php > MakeFont("/<font location>/Rockford.ttf", "/<font location>/Rockford.afm");
php > exit

You should see two new files, Rockford.php and Rockford.z in the current directory. Copy these two files to the 'fonts' directory in the fpdf installation directory.

cp Rockford.z Rockford.php /<...>/fpdf/font/

At this point, the installation of the new font into FPDF is done.

To use your font when generating a PDF, you must first import the font as follows.

$fpdf->AddFont('Rockford', '', 'Rockford.php');

You can then use the font when needed in your script. For example, to set the font to Rockford size 8, you would write the following statement.

$fpdf->SetFont('Rockford', '', 8);


Bringing this back up as there's a pretty quick and easy converted online now - fPDF Font File Converter


Unfortunately this is way more difficult than it should be, albeit I got it working. The link below is a great reference, but I couldn't get fondu to install so I had to use TrueType on Windows, TransType Pro.

http://www.eiriks.net/2007/09/13/custom-font-with-fpdf-on-os-x-ttf2pt1-fondu/

I did just find this HTML to PDF generator and may look into that, it seems pretty easy to customize compared to FPDF. http://www.digitaljunkies.ca/dompdf/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜