Devin Crossman
Devin Crossman

Reputation: 7592

tcpdf custom font is not being used

I'm using the TCPDF library to generate a PDF file with PHP. I want to use a custom font so I used the addTTFfont method to add my custom TrueType font files. The font I am trying to add is "Aller" from fontsquirrel.com

$aller = $pdf->addTTFfont($_SERVER['DOCUMENT_ROOT'].'/includes/fonts/Aller/Aller_Rg.ttf', 'TrueTypeUnicode', '', 32);

This created the files aller_rg.php, aller_rg.ctg.z, and aller_rg.z in my TCPDF fonts folder. The K_PATH_FONTS constant points to this directory. The addTTFfont method returns the string name of the font. It would return false if there was an error so the problem is probably not here..

I then tried to use the font

$pdf->SetFont($aller, '', 16); // or $pdf->SetFont('aller_rg', '', 16);
$pdf->Write(0,"abcdefg",'',0,'L',true,0,false,true,0);

The pdf is generated without any errors. When viewsed in the browser preview the font is clearly not aller but just a generic sans-serif.. When I open the pdf in Mac's Preview application the sections that are using the aller font are blank (no text displays).

Anyone know what I'm doing wrong?

Upvotes: 1

Views: 4745

Answers (2)

Toxiro
Toxiro

Reputation: 611

I had the same problem:

The TCPDF converted font did not display, but the one converted with the following link did: http://www.xml-convert.com/en/convert-tff-font-to-afm-pfa-fpdf-tcpdf

So I compared the two and found out that xml-convert.com was using "TrueType" instead of "TrueTypeUnicode" as font type. For me it worked to change the argument to "TrueTypeUnicode". Try:

$aller = $pdf->addTTFfont($_SERVER['DOCUMENT_ROOT'].'/includes/fonts/Aller/Aller_Rg.ttf', 'TrueType', '', 32);

Upvotes: 1

Devin Crossman
Devin Crossman

Reputation: 7592

Got it to work by using this tool

http://www.xml-convert.com/en/convert-tff-font-to-afm-pfa-fpdf-tcpdf

it generates a .php, .z, and .afm file that you put in the TCPDF fonts directory. I'm still not sure what the problem was. the addTTFfont() method doesn't create the .afm file so maybe that's it?

Upvotes: 2

Related Questions