ezpdf 文档中的特殊字符 (ö)

发布于 2024-09-15 02:10:37 字数 487 浏览 2 评论 0原文

我使用 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';

所有这些都不起作用,角色要么不显示,要么有奇怪的标记。

我还能尝试什么?

更新:下载了新版本,问题仍然存在:请参见此处:alt text

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: alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

指尖上的星空 2024-09-22 02:10:37

您是否以 UTF-8 格式从 MySQL 获取数据?如果不是,在将其传递给 PDF 生成器之前,它可能已经在该步骤中进行了双重编码?

你尝试过吗?

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
mysql_set_charset('utf8',$link);

编辑:哦抱歉,我误会了。但是,请注意,数据库中的内容可能是 utf-8 编码的或以任何其他格式编码的,无论您将数据库设置为包含什么内容。

您能否准确地向我们展示您在各个步骤中获得的角色?

编辑2:

我下载了: http://www.ros.co .nz/pdf/downloads.php?f=pdfClassesAndFonts_009e.zip 来自 http:// www.ros.co.nz/pdf/

并在我解压 zip 的同一目录中运行此脚本:

<?php
include 'class.ezpdf.php';
$pdf = new Cezpdf('a4','portrait');
$pdf->ezText("\xf6\n",0,array('justification'=>'centre'));
$pdf->ezStream();
?>

并至少在文档中获得正确的 ö 。

如果像您所说的检测到的编码是 utf-8,请尝试在其周围包装 utf8_decode:

<?php
include 'class.ezpdf.php';
$pdf = new Cezpdf('a4','portrait');
$pdf->ezText(utf8_decode("\xc3\xb6\n"),0,array('justification'=>'centre'));
$pdf->ezStream();
?>

如果它仍然不起作用,也许您有旧版本的 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?

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
mysql_set_charset('utf8',$link);

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:

<?php
include 'class.ezpdf.php';
$pdf = new Cezpdf('a4','portrait');
$pdf->ezText("\xf6\n",0,array('justification'=>'centre'));
$pdf->ezStream();
?>

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:

<?php
include 'class.ezpdf.php';
$pdf = new Cezpdf('a4','portrait');
$pdf->ezText(utf8_decode("\xc3\xb6\n"),0,array('justification'=>'centre'));
$pdf->ezStream();
?>

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.

机场等船 2024-09-22 02:10:37

不幸的是,没有办法告诉 Cezpdf 接受 UTF-8 编码的文本。通过此代码片段,您可以解决这个问题:

class UTF8_Cezpdf extends Cezpdf {
    function ezText($text, $size=0, $options=array(), $test=0) {
        $text = utf8_decode($text); // or use mb_convert_encoding(), according to your needs
        return parent::ezText($text, $size, $options, $test);
    }
}

当然,您必须实例化新类来代替旧类:

$pdf = new UTF8_Cezpdf('a4','portrait');

一个缺点:表格中的文本(通过 $pdf->ezTable() 添加)将无法正确编码。

Unfortunatly there is no way to tell Cezpdf to accept UTF-8 encoded Text. With this snippet you can walkaround this issue:

class UTF8_Cezpdf extends Cezpdf {
    function ezText($text, $size=0, $options=array(), $test=0) {
        $text = utf8_decode($text); // or use mb_convert_encoding(), according to your needs
        return parent::ezText($text, $size, $options, $test);
    }
}

Of course you have to instantiate the new class insteat of the old one:

$pdf = new UTF8_Cezpdf('a4','portrait');

One drawback: Text in tables (added via $pdf->ezTable() ) will not be properly encoded.

小帐篷 2024-09-22 02:10:37

我尝试了这篇文章中的所有内容,但没有运气。偶然发现一篇博文提出了以下建议:

将以下行添加到 class.ezpdf.php 中的函数 ezProcessText()addText()class.pdf.php

$text = mb_convert_encoding($text, "ISO-8859-1", "UTF-8");

就我而言,我只是将其添加到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() in class.ezpdf.php and addText() in class.pdf.php:

$text = mb_convert_encoding($text, "ISO-8859-1", "UTF-8");

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/)

今天小雨转甜 2024-09-22 02:10:37

特殊字符列表可以在 http://www.utf8-chartable.de/ 中找到只需在开头添加“\x”,您就可以获得pdf中的所有特殊字符。

ei:

  1. "\x24" => $
  2. "\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:

  1. "\x24" => $
  2. "\x5b" => [

$pdfObject->ezText("\x5b"); will print [

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文