dompdf字符编码UTF-8 [英] dompdf character encoding UTF-8

查看:303
本文介绍了dompdf字符编码UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用正确的字符创建pdf,但有?字符。
我创建了一个测试php文件,其中Im试图指出最好的解决方案。如果我在浏览器打开html我看起来像确定

Im trying to create pdf with correct characters, but there are "?" chars. I created a test php file, where Im trying to fing the best solution. If Im open in the browser the html I looks like ok

UTF-8 --> UTF-8 : X Ponuka číslo € černý Češký 

但是当我看到pdf, / p>

But when I look into the pdf I see this

UTF-8 --> UTF-8 : X Ponuka ?íslo € ?erný ?ešký 

这里是我所有的代码: p>

Here is my all code:

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>č s š Š</title>
</head>
<body>
<?php 

require_once("dompdf/dompdf_config.inc.php");
$tab = array("UTF-8", "ASCII", "Windows-1250", "ISO-8859-2", "ISO-8859-1", "ISO-8859-6", "CP1256"); 
$chain = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <style></style><title>č s š Š</title></head><body>';
foreach ($tab as $i) 
    { 
        foreach ($tab as $j) 
        { 
            $chain .= "<br> $i --> $j : ".iconv($i, $j, 'X Ponuka číslo € černý Češký <br>'); 
        } 
    } 
$chain .= '<p style="font-family: firefly, verdana, sans-serif;">??????X Ponuka číslo € černý Češký <br></p></body></html>';
echo $chain; 
echo 'X Ponuka číslo € černý Češký <br>'; 

$filename = 'pdf/_1.pdf';
$dompdf = new DOMPDF();
$dompdf->load_html($chain, 'UTF-8');
$dompdf->set_paper('a4', 'portrait'); // change these if you need to
$dompdf->render();
file_put_contents($filename, $dompdf->output());

?> 
</body>
</html>

我做错了什么?我尝试了许多选项,我发现:(任何想法?

What Im doing wrong? I tried many many options which I found :( Any idea?

推荐答案

您应该阅读 Unicode How-to 。主要的问题是你没有指定支持你的字符的字体,看起来你读过因为你正在使用该文档的字体示例,但是该示例并不是要全局应用于任何文档,dompdf默认不包括firefly(一种中文字体)或Verdana。

You should read over the Unicode How-to again. The main problem is that you don't specify a font that supports your characters. It looks like you've read the how-to, because you're using the font example from that document. However the example was not meant to apply globally to any document, dompdf doesn't include firefly (a Chinese character font) or Verdana by default.

如果你没有指定字体,那么dompdf会回到只支持Windows ANSI编码的核心字体之一(Helvetica,Times Roman,Courier)。

If you do not specify a font then dompdf falls back to one of the core fonts (Helvetica, Times Roman, Courier) which only support Windows ANSI encoding. So always be sure to style your text with a font that supports Unicode encoding and has the characters you need to display.

使用dompdf 0.6.0,您可以使用包含的Deja Vu字体,因此以下内容工作(只是HTML):

With dompdf 0.6.0 you can use the included Deja Vu fonts. So the following should work (just the HTML):

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style>
  body { font-family: DejaVu Sans, sans-serif; }
</style>
<title>č s š Š</title>
</head>
<body>
  <p>??????X Ponuka číslo € černý Češký <br></p>
</body>
</html>

这篇关于dompdf字符编码UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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