Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TCPDF - embedded ttf fonts not showing when PDF is viewed on iPad

I've created a website that dynamically creates PDF's using tcpdf and embeds the fonts into the PDF. The user can select from a range of standard fonts like Arial, Verdana etc. Then the system chooses a ttf font directly from my server and embeds using the code below. The text with that font could be seen fine on most pdf viewers but iPad/iPhone's viewer wasn't displaying it. I downloaded a new (random) version of Arial.ttf as a test(not sure of the difference in the file, but it seems to display fine now.

I need to do this for a number of fonts but am shooting in the dark a bit because I don't know what in the font might cause it not to be embedded. Does anyone know what in the ttf fonts would cause it not to be displays? Shows fine on other viewers and shows to be embedded in Acrobat document properties?

Thanks

$fontname = $pdf->addTTFfont('/tcpdf/fonts/custom/'.$ttfFile.'.ttf', 'TrueTypeUnicode', '', 32);

// use the font

$pdf->SetFont($fontname, '', $fontPoints, '', 'false');
like image 376
user1916116 Avatar asked Mar 07 '13 20:03

user1916116


1 Answers

Your parameter for $subset is wrong. You set it to 'false' (with the quotes). It should be boolean true.

    <?php
          ...
          // Wrong
          $pdf->SetFont($fontname, '', $fontPoints, '', 'false');

          // Right
          $pdf->SetFont($fontname, '', $fontPoints, '', true); 
          ...
    ?>

Why does it work?

Because it embeds the whole font, not only a subset. The trick is to set the parameter $subset in method $pdf->SetFont() to true.

http://www.tcpdf.org/doc/code/classTCPDF.html#a471562985997be1573d387f0aeae6964

PDF is working with

iPad (IOS 7), iPhone (IOS 7), Windows 7, MACOSX 10.9.

My environment for PDF Creation

Apache 2 on MAC 10.9, PHP 5.3.x, TCPDF v6.0.078

Files

Example PDF and a PHP Script to create it

like image 189
Uwe Schmelzer Avatar answered Dec 21 '22 09:12

Uwe Schmelzer