ezpdf 文档中的特殊字符 (ö)
我使用 ezPDF(版本 0.9)创建 PDF 文档。
我在文档中插入的数据来自 MySQL 数据库,编码为:“latin1_swedish_ci”。
特殊字符(尤其是 ö,现在最重要)在文档中显示为希腊史前代数(字面值)。
到目前为止我已经尝试过:
iconv();
htmlspecialchars();
htmlentities();
mb_convert_encoding();
utf8_encode();
include with chr(148);
mb_detect_encoding() returns 'UTF-8';
所有这些都不起作用,角色要么不显示,要么有奇怪的标记。
我还能尝试什么?
更新:下载了新版本,问题仍然存在:请参见此处:
Im creating a PDF document with ezPDF (version 0.9).
The data I insert in the document is from a MySQL database with encoding: "latin1_swedish_ci".
Special characters (especially ö, which matters the most now) are displayed like Greek pre historical algabra (literal) in the document.
What I have tried so far:
iconv();
htmlspecialchars();
htmlentities();
mb_convert_encoding();
utf8_encode();
include with chr(148);
mb_detect_encoding() returns 'UTF-8';
All of these wont work, the character is either not displayed or has a strange markup.
What else can I try?
UPDATE: Downloaded the new version, problem still remains: See here:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否以 UTF-8 格式从 MySQL 获取数据?如果不是,在将其传递给 PDF 生成器之前,它可能已经在该步骤中进行了双重编码?
你尝试过吗?
编辑:哦抱歉,我误会了。但是,请注意,数据库中的内容可能是 utf-8 编码的或以任何其他格式编码的,无论您将数据库设置为包含什么内容。
您能否准确地向我们展示您在各个步骤中获得的角色?
编辑2:
我下载了: http://www.ros.co .nz/pdf/downloads.php?f=pdfClassesAndFonts_009e.zip 来自 http:// www.ros.co.nz/pdf/
并在我解压 zip 的同一目录中运行此脚本:
并至少在文档中获得正确的 ö 。
如果像您所说的检测到的编码是 utf-8,请尝试在其周围包装 utf8_decode:
如果它仍然不起作用,也许您有旧版本的 ezpdf?看起来他们确实必须在整个时代添加一些针对非 ASCII 字符的修复,尽管是很久以前的事了。
Are you fetching the data from MySQL as UTF-8? If not,it might be double-encoded already in that step before passing it to the PDF generator?
Have you tried?
Edit: Oh sorry, I misunderstood. BUT, beware, the content in the DB might be utf-8 encoded or encoded in any other format no matter what you have set the database to supposedly contain.
Can you show us exactly what characters you get at the various steps?
Edit2:
I downloaded: http://www.ros.co.nz/pdf/downloads.php?f=pdfClassesAndFonts_009e.zip from http://www.ros.co.nz/pdf/
and run this script in the same dir I unpacked the zip:
and get a proper ö in the document at least.
if like you said the detected encoding is utf-8, try wrapping a utf8_decode around it:
If it still doesn't work, maybe you have an older version of ezpdf? It seems they did had to add some fixes for non-ascii characters throughout the times, although long ago.
不幸的是,没有办法告诉 Cezpdf 接受 UTF-8 编码的文本。通过此代码片段,您可以解决这个问题:
当然,您必须实例化新类来代替旧类:
一个缺点:表格中的文本(通过 $pdf->ezTable() 添加)将无法正确编码。
Unfortunatly there is no way to tell Cezpdf to accept UTF-8 encoded Text. With this snippet you can walkaround this issue:
Of course you have to instantiate the new class insteat of the old one:
One drawback: Text in tables (added via $pdf->ezTable() ) will not be properly encoded.
我尝试了这篇文章中的所有内容,但没有运气。偶然发现一篇博文提出了以下建议:
将以下行添加到
class.ezpdf.php
中的函数ezProcessText()
和addText()
中class.pdf.php
:就我而言,我只是将其添加到
class.pdf.php
,但它成功了!(来源:http ://natealberg.wordpress.com/2010/07/26/ezpdf-and-special-characters-copyright-trademark-and-registered-trademark/)
I tried everything in this post but without luck. Stumbled upon a blogpost with suggests the following:
Add the following line to functions
ezProcessText()
inclass.ezpdf.php
andaddText()
inclass.pdf.php
:In my case, I just added it to
class.pdf.php
, but it did the trick!(Source: http://natealberg.wordpress.com/2010/07/26/ezpdf-and-special-characters-copyright-trademark-and-registered-trademark/)
特殊字符列表可以在 http://www.utf8-chartable.de/ 中找到只需在开头添加“\x”,您就可以获得pdf中的所有特殊字符。
ei:
"\x24"
=>$
"\x5b"
=>[
$pdfObject->ezText("\x5b");
将打印[
A list of special characters could be found at http://www.utf8-chartable.de/ and just by adding "\x" at the beginning you can get all the special characters in your pdf.
ei:
"\x24"
=>$
"\x5b"
=>[
$pdfObject->ezText("\x5b");
will print[