【问题标题】:dompdf pdf creation problems with accented characters带有重音字符的 dompdf pdf 创建问题
【发布时间】:2011-12-14 12:23:48
【问题描述】:

我正在使用带有 Codeigniter (php 5 ++) 的 dompdf 库,一切都很好,但是在显示 pdf 时我仍然遇到重音字符的问题。

它用奇怪的字符(非 utf8 字符)替换所有 à ò è ù 等。

envoirment 是全局 utf-8 我如何调试/尝试解决这个问题的方法?

我在创建 pdf 之前尝试通过 php 设置内容类型,但没有任何改变......然后我放入 pdf 的相同 html 保存在 db 中,看起来没问题,重音字符没问题,所以我认为这是一个主要的 dompdf 问题,我认为它设置了一些奇怪的编码:P

谁能帮我调试和修复?

[已编辑]

这是我正在创建的 pdf 文档的 HTML 示例。

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html>
                 <head>
                 <meta http-equiv=“Content-Type” content=“text/html; charset=utf-8” /> 
                 <style type="text/css">
                 body{margin:0 auto;padding:0px;font-size:10px;font-family:helvetica, sans-serif;}
                 #wrapper{margin:30px;}
                 #logo{margin:2px;background-image:url(http://localhost/img/logo.png);background-repeat:no-repeat;}
                 #ricevuta{font-weight:bold;margin-top:4px;padding:5px;font-size:14px;}
                 #order-n{color:#fff;padding:3px;font-weight:bold;background-color:#785a3b;}
                 #address-order{background-color:#ebe0d5;padding:5px;}
                 .h1-p{font-weight:bold;font-size:14px;margin:5px;}
                 table{width:100%;}
                 table tr{width:100%;padding:4px;}
                 .align-right{text-align:right;}
                 thead {background-color:#785a3b;color:#fff;font-weight:bold;}
                 #table-total{background-color:#ebe0d5;}
                 </style>
                 </head>
                 <body>
                 <div id="wrapper">
                 <div id="logo">
                  <img src="http://localhost/img/logo.png" />
                 </div>
                 <div id="ricevuta">
                 Ricevuta Ordine
                 </div>
                <div id="order-n">
                 ORDINE numero - <strong>1 - Data (15-08-2011)</strong>
                </div>
                <p class="h1-p">Indirizzo Spedizione</p>
                <div id="address-order">
                <p>
                <strong></strong><br>
                <strong>sdfsdf sdfsd</strong><br>
                sfgfdg (sdgfdg), Austria, 45666<br>
                sdfsdf<br>
                telefono fisso: <br>
                telefono mobile: <br>
                 </p>
                 </div>
               <p class="h1-p">Riepilogo Ordine</p>
               <table>
               <thead>
               <tr>
               <td><strong>Nome Prodotto</strong></td>
               <td><strong>Codice Prodotto</strong></td>
               <td><strong>Quantita</strong></td>
               <td><strong>Prezzo</strong></td>
               </tr>
               </thead>

                    <tr>
                    <td>3423rf</td>
                    <td><strong># </strong></td>
                    <td><strong>2</strong></td>
                    <td><strong>29,70 euro</strong></td>
                    </tr>
               </table>
               <table id="table-total">
               <tr class="align-right">
               <td></td>
               <td></td>
               <td></td>
               <td><strong>Sub-totale:</strong> euro 59,40</td>
               </tr>
               <tr class="align-right">
               <td></td>
               <td></td>
               <td></td>
               <td><strong> Spedizione:</strong> euro 26,50</td>
               </tr>

                <tr class="align-right">
               <td></td>
               <td></td>
               <td></td>
               <td><strong>Totale (tax,incluse):</strong> euro 85,90</td>
               </tr>
                </table>
                </div>
                </body></html>

【问题讨论】:

  • 不明白我是否需要通过 shell 命令运行或安装软件包,这样我就无法使用标准主机。还尝试启用 UNICODE 支持code.google.com/p/dompdf/wiki/…,但它不起作用:(而且我没有在文档中指定的文件中创建 DOMPDF_UNICODE_ENABLED 行:/ 我补充说,但没有,添加时没有任何改变: (
  • @MarcB 好的,我将 dompdf 更新为最新版本,并且默认启用 UNICODE 支持,问题仍然存在 :( 重音字符转换为非 utf8 字符 :(
  • 如果您已按照该页面上的所有说明进行操作 you should be ok。检查示例站点 (.../dompdf/www/setup.php) 中的设置页面,看看您是否有任何配置问题。
  • @Ispuk 您可以尝试 Deja Vu Sans(或其他 Deja Vu 字体之一)。这些没有进入 beta 2,但您可以从 code repository(或 download a nightly)获取它们。

标签: php codeigniter utf-8 pdf-generation dompdf


【解决方案1】:

在将$html 传递给dompdf 之前,我使用utf8_decode($html) 解决了我的问题。这意味着重音字符现在可以使用。

【讨论】:

  • 很高兴为您工作。 utf8_decode() 在 iso-8859-1 中无法表示字符时可能会破坏文本,但听起来您没有使用无法处理的字符。如果您需要再次尝试使用 UTF8,稳定的 0.6.0 版本将在可用性和功能方面有显着改进。
猜你喜欢
  • 2021-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-26
  • 1970-01-01
  • 1970-01-01
  • 2012-02-01
  • 2014-11-23
相关资源
最近更新 更多