dompdf special character showing question mark?

2019-07-28 21:00发布

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

For example, Enter image description here.

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条回答
神经病院院长
2楼-- · 2019-07-28 21:47

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

查看更多
登录 后发表回答