使用TCPDF生成的UTF-8 PDF在Adobe Acrobat中显示正常,但在Illustrator和Google预览中已损坏 [英] UTF-8 PDF generated with TCPDF showing up fine in Adobe Acrobat but corrupted in Illustrator and Google preview

查看:158
本文介绍了使用TCPDF生成的UTF-8 PDF在Adobe Acrobat中显示正常,但在Illustrator和Google预览中已损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PHP和TCPDF生成以utf8编码的在线发票.我已经按照tcpdf网站上的教程使用PT-sans .ttf文件创建了字体定义文件.

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.

使用Adobe Reader打开时,生成的pdf文件看起来不错(正确显示重音符号).但是,一旦使用Adobe Illustrator打开pdf文件,您就会看到普通的ascii字符和缺少的字符符号的混合体.在gmail预览中作为附件打开时,根本不会显示任何文字,只会显示图片.

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.

我在Foxit阅读器上的行为也不一致.在一台计算机(安装了字体)上可以,但是在另一台计算机(未安装字体)上损坏了.

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(在左侧)和Foxit阅读器的打印屏幕: http://dl.dropbox.com/u/14647415/illustrator%20and%20foxit.jpg

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

这是损坏的文件的副本: http://dl.dropbox .com/u/14647415/2011040-3.pdf

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

PDF的大小为±200kB,因此似乎正确嵌入了字体.

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

似乎任何utf8字体都会发生这种情况,并嵌入了tcpdf网站上描述的过程.当我尝试tcpdf库附带的核心cid字体时,缺少重音字符或将其替换为?,但是在Illustrator中也可以使用总体布局和文本.附加的utf-8字体(如Dejavusans)也显示为损坏.

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.

我使用'UTF-8'作为传递给tcpdf构造函数的参数.

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

XTCPDF类扩展了TCPDF {

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?

非常感谢您.

p.

推荐答案

问题显然是由TCPDF自动设置字体引起的.这会导致字符集出现问题(字符已移位","0"解释为"A"等),而不是Acrobat.

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.

解决方案正在设置:

$pdf->setFontSubsetting(false);

,然后根据要使用的字符集手动设置字体的字体,以减小生成的文件大小.

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

这篇关于使用TCPDF生成的UTF-8 PDF在Adobe Acrobat中显示正常,但在Illustrator和Google预览中已损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆