8
votes

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');
1
What do you mean by "not displaying" - the text was actually completely not there? And can you share one of those PDFs so that it can be looked at? - David van Driessche
Hi, thanks for your reply, fonts were visible on chrome pdf reader and through safari but not through the standard viewer on iPhone / iPad. Here is an example with a selection of fonts, all show through most viewers, some are missing on iPhone. They are apparently 'embedded subsets' according to Acrobat, any ideas would be very helpful. s316279697.websitehome.co.uk/joe/banner790.pdf - user1916116
I ran your file through callas pdfToolbox preflight (warning, I'm affiliated with this company) and I see two perhaps strange things. First of all, your file also contains two Helvetica fonts that apparently aren't used on the page (and that are not embedded). Your file also comes back with a number of errors for the Palatino font used. Is this the font that isn't displayed? - David van Driessche

1 Answers

3
votes

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