dompdf特殊字符显示问号? [英] dompdf special character showing question mark?

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

问题描述

我已使用dompdf 0.5.1生成PDF文件。但是特殊字符不能正确显示。

I have used dompdf 0.5.1 for generating PDF files. But the special characters are not properly showing.

例如,。

在生成的PDF文件中显示类似 –â€的内容。

It is showing something like â€" “ in the generated PDF file.

我使用了类似
< meta http-equiv = Content-Type content = text / html; charset = UTF-8 />

I used UTF-8 encoding like <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> in the HTML page which is rendered by the dompdf.

在将其发送到dompdf之前,我也使用了编码,例如
$ dompdf-> load_html(utf8_decode($ html));

I also have used the encoding before sending it to dompdf, like $dompdf->load_html(utf8_decode($html));.

但是我得到了标记而不是上述字符。

But I get ? marks instead of the above characters.

如何解决上述问题?

推荐答案

Dompdf 0.5.1对Windows ANSI编码不支持的字符的支持有限。如果需要支持这些字符,则至少应更新为 Dompdf 0.6 .2 。尽管我建议您尽可能使用 Dompdf 0.7.0

Dompdf 0.5.1 has limited support for characters that aren't supported by Windows ANSI encoding. If you need to support these characters you should update to, at the very least, Dompdf 0.6.2. Though I'd recommend using Dompdf 0.7.0 if you can.

您需要提供支持字符的字体(请参见 Unicode操作方法),但是只要您不尝试呈现CJK字符,您就可以依靠随附的DejaVu字体。

You'll need to supply a font that supports your characters (see the Unicode How-To), but so long as you're not trying to render CJK characters you can probably rely on the included DejaVu fonts.

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <style>
    * { font-family: DejaVu Sans, sans-serif; }
  </style>
</head>
<body>
  <p>—</p>
</body>
</html>

此外,您应该从不使用 utf8_decode( ),因为它将破坏性地转换为iso-8859-1编码。破坏性的意思是它会更改不能直接转换为带问号(?)的iso-8859-1的字符。

Also, you should never use utf8_decode() as it will destructively convert to iso-8859-1 encoding. By destructively I mean that it will change characters it can't directly convert to iso-8859-1 in question marks (?).

这篇关于dompdf特殊字符显示问号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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