dompdf special character showing question mark?

流过昼夜 提交于 2019-12-23 22:03:26

问题


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

For example, .

It is showing something like – “ in the generated PDF file.

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.

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.

How do I solve the above problem?


回答1:


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.

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>

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 (?).



来源:https://stackoverflow.com/questions/38718881/dompdf-special-character-showing-question-mark

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!