本文介绍了如何使用Zend Framework生成pdf文件_with_ utf-8多字节字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Zend Framework 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.

源文本以及执行此工作的php源文件均以utf-8编码.

Source text is encoded in utf-8, as well as the php source file which does the job.

在此先感谢您的帮助;)

Thank you in advance for your help ;)

P.S.我运行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

See also this bug log: http://framework.zend.com/issues/browse/ZF-3649

这篇关于如何使用Zend Framework生成pdf文件_with_ utf-8多字节字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 21:52