如何使用 Zend Framework 生成 _with_ utf-8 多字节字符的 pdf 文件 [英] How to generate pdf files _with_ utf-8 multibyte characters using Zend Framework

查看:29
本文介绍了如何使用 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

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

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