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

只愿长相守 提交于 2019-12-05 22:44:02

问题


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:


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



来源:https://stackoverflow.com/questions/15280647/tcpdf-embedded-ttf-fonts-not-showing-when-pdf-is-viewed-on-ipad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!