dompdf pdf 创建问题与重音字符

发布于 2024-12-12 00:17:38 字数 4408 浏览 0 评论 0原文

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

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

环境是全局 utf-8 我如何调试/尝试此问题的解决方案?

我尝试在创建pdf之前通过php设置内容类型,但没有任何变化...然后我放入pdf中的相同html保存在数据库中,它看起来不错,重音字符也可以,所以我认为这是一个主要的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>

i'm using the dompdf library with Codeigniter (php 5 ++) , everythings works great, but i'm still having problems with accented chracters when displaying the pdf.

it replaces all the à ò è ù etc .. with strange chars (non-utf8 chars).

the envoirment is globally utf-8 how can i debug/try solutions for this problem?

i tryed setting the content type via php before creating the pdf but nothing changes ... then the same html i put in pdf is saved in db and it looks ok, accented chars are ok so it's a main dompdf problem i think, which sets some strange encoding i think :P

anyone can help me debugging and fixing?

[EDITED]

this is the HTML example of pdf documents i'm creating.

 <!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>

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

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

发布评论

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

评论(1

月牙弯弯 2024-12-19 00:17:38

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

I fixed my problem using utf8_decode($html) before passing $html to dompdf. This means that accented chars now work.

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