如何使用 Zend Framework 生成 _with_ utf-8 多字节字符的 pdf 文件
我对 Zend 框架 Zend_Pdf 类有一个小"问题.从生成的 pdf 文件中删除多字节字符.例如.当我写 aąbcčdeę 时,它变成了 abcd,立陶宛字母被去掉了.
I've got a "little" problem with Zend Framework Zend_Pdf class. Multibyte characters are stripped from generated pdf files. E.g. when I write aąbcčdeę it becomes abcd with lithuanian letters stripped.
我不确定这是特别的 Zend_Pdf 问题还是一般的 php.
I'm not sure if it's particularly Zend_Pdf problem or php in general.
源文本以 utf-8 编码,以及完成这项工作的 php 源文件.
Source text is encoded in utf-8, as well as the php source file which does the job.
预先感谢您的帮助;)
附言我运行 Zend Framework v. 1.6 并使用 FONT_TIMES_BOLD 字体.FONT_TIMES_ROMAN 确实有效
P.S. I run Zend Framework v. 1.6 and I use FONT_TIMES_BOLD font. FONT_TIMES_ROMAN does work
推荐答案
Zend_Pdf
在 Zend Framework 1.5 版中支持 UTF-8.但是,标准 PDF 字体仅支持 Latin1 字符集.这意味着您不能使用 Zend_Pdf_Font::FONT_TIMES_BOLD
或任何其他内置"字体.要使用特殊字符,您必须加载另一种包含来自其他字符集的字符的 TTF 字体.
Zend_Pdf
supports UTF-8 in version 1.5 of Zend Framework. However, the standard PDF fonts support only the Latin1 character set. This means you can't use Zend_Pdf_Font::FONT_TIMES_BOLD
or any other "built-in" font. To use special characters you must load another TTF font that includes characters from other character sets.
我使用 Mac OS X,所以我尝试了以下代码,它生成了一个包含正确字符的 PDF 文档.
I use Mac OS X, so I tried the following code and it produces a PDF document with the correct characters.
$pdfDoc = new Zend_Pdf();
$pdfPage = $pdfDoc->newPage(Zend_Pdf_Page::SIZE_LETTER);
// load TTF font from Mac system library
$font = Zend_Pdf_Font::fontWithPath('/Library/Fonts/Times New Roman Bold.ttf');
$pdfPage->setFont($font, 36);
$unicodeString = 'aąbcčdeę';
$pdfPage->drawText($unicodeString, 72, 720, 'UTF-8');
$pdfDoc->pages[] = $pdfPage;
$pdfDoc->save('utf8.pdf');
另见此错误日志:http://framework.zend.com/issues/浏览/ZF-3649
相关文章