問題描述
我對 Zend 框架 Zend_Pdf 類有一個小"問題.從生成的 pdf 文件中刪除多字節(jié)字符.例如.當(dāng)我寫 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.
預(yù)先感謝您的幫助;)
附言我運(yùn)行 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.但是,標(biāo)準(zhǔn) PDF 字體僅支持 Latin1 字符集.這意味著您不能使用 Zend_Pdf_Font::FONT_TIMES_BOLD
或任何其他內(nèi)置"字體.要使用特殊字符,您必須加載另一種包含來自其他字符集的字符的 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
這篇關(guān)于如何使用 Zend Framework 生成 _with_ utf-8 多字節(jié)字符的 pdf 文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!