duanpa2143 2011-05-09 13:20
浏览 179
已采纳

使用TCPDF生成的UTF-8 PDF在Adobe Acrobat中显示正常,但在Illustrator和Google预览中已损坏

I use PHP and TCPDF to generate online invoices encoded in utf8. I've created font definition files following the tutorial on the tcpdf website using PT-sans .ttf file.

Generated pdf files look fine (accents are displayed correctly) when opened with Adobe Reader. But as soon as you open the pdf file with Adobe Illustrator, you'll see a mix of normal ascii characters and missing characters signs. When opened as attachment in the gmail preview, no text is displayed at all, just images will show up.

I also get unconsistent behavior with Foxit reader. It was ok on one computer (with font installed), but corrupted on another (without the font installed).

Illustrator (on the left) and Foxit reader printscreen: http://dl.dropbox.com/u/14647415/illustrator%20and%20foxit.jpg

Here is a copy of the corrupted file: http://dl.dropbox.com/u/14647415/2011040-3.pdf

PDF's size is ±200kB, so font seems to be embeded correctly.

This seems to happen with any utf8 font, embeded with procedure described on the tcpdf website. When I tried the core cid fonts, that came with the tcpdf library, accented characters were missing, or have been replaced with ?, but the overal layout and text were ok in Illustrator, too. Attached utf-8 fonts like Dejavusans are showing up corrupted, too.

I use 'UTF-8' as a param passed into tcpdf constructor.

class XTCPDF extends TCPDF {

function __construct(){
    parent::__construct('P', 'mm', 'A4', true, 'UTF-8', false);
    ...
}
...

}

Do you have any ideas on what could be causing this?

Thank you very much in advance.

p.

  • 写回答

1条回答 默认 最新

  • duanchi4544 2011-05-10 11:09
    关注

    Problem was obviously caused by TCPDF automatically subsetting the font. This caused problems with charset (characters were "shifted", '0' interpreted as 'A' etc.) in aplications other than Acrobat.

    Solution to this is setting:

    $pdf->setFontSubsetting(false);
    

    and subsetting your font manually to reduce the resulting file size, based on charset you want to use.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)