如何使用Zend Framework生成具有8个多字节字符的pdf文件


How to generate pdf files _with_ utf-8 multibyte characters using Zend Framework

我在Zend Framework Zend_Pdf类中遇到了一个"小"问题。从生成的pdf文件中删除多字节字符。例如,当我写一个brow bcčdeÉ时,它变成了去掉立陶宛字母的abcd。

我不确定是Zend_Pdf问题还是php问题。

源文本编码在utf-8中,还有完成这项工作的php源文件。

提前感谢您的帮助;)

附言:我运行Zend Framework 1.6版,使用FONT_TIMES_BOLD字体。FONT_TIMES_ROMAN确实工作

Zend_Pdf在Zend Framework 1.5版本中支持UTF-8。但是,标准PDF字体仅支持Latin1字符集。这意味着您不能使用Zend_Pdf_Font::FONT_TIMES_BOLD或任何其他"内置"字体。若要使用特殊字符,必须加载另一种TTF字体,其中包含其他字符集的字符。

我使用Mac OS X,所以我尝试了以下代码,它生成了一个具有正确字符的PDF文档。

$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/browse/ZF-3649

我相信Zend_Pdf在1.5中得到了UTF-8支持-您运行的是什么版本的Zend Framework?

还有,你想用什么字体渲染?你试过其他字体吗?

您是否确保将字符编码设置为手册中的示例?

// Draw the string on the page
$pdfPage->drawText($unicodeString, 72, 720, 'UTF-8');

如果你不得不使用粗体字体,也许可以试试其他粗体字体?

Zend_Pdf_Font::FONT_COURIER_BOLD
Zend_Pdf_Font::FONT_TIMES_BOLD
Zend_Pdf_Font::FONT_HELVETICA_BOLD

ZF v.1.6,TIMES_BOLD(据我所知,这是将文本加粗的唯一方法?)