gpt4 book ai didi

encoding - dompdf特殊字符显示问号?

转载 作者:行者123 更新时间:2023-12-04 13:43:07 25 4
gpt4 key购买 nike

我使用 dompdf 0.5.1 来生成 PDF 文件。但是特殊字符没有正确显示。

例如,Enter image description here .

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

我使用了 UTF-8 编码,例如<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />在由 dompdf 呈现的 HTML 页面中。

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

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

我如何解决上述问题?

最佳答案

Dompdf 0.5.1 对 Windows ANSI 编码不支持的字符的支持有限。如果您需要支持这些字符,至少应该更新到 Dompdf 0.6.2 .虽然我建议使用 Dompdf 0.7.0如果你可以的话。

您需要提供一种支持您的字符的字体(请参阅 Unicode How-To ),但只要您不尝试渲染 CJK 字符,您就可以依赖包含的 DejaVu 字体。

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

关于encoding - dompdf特殊字符显示问号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38718881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com