转换 PDF 文件中的杂项符号

convert Miscellaneous Symbols in PDF file

我正在尝试使用 dompdf 创建 pdf 文件 我有那些杂项符号 具体 ☐ 或这个

它们没有出现在生成的 PDF 中,而是我得到了问号 ?

替换字符

我尝试了所有这些解决方案 dompdf special characters

Special characters with dompdf and php

实际上,这更像是一个一般性的 "how do I get dompdf to support X character" 问题。问题与字符集编码有关(与使用的字体有关)。

首先,您需要指定支持您指定字符的字符集编码。在几乎所有情况下,您都应该编码为 UTF-8。

其次,您需要使用支持所需特定字形的字体,并且需要将字体加载到 dompdf 中。对于您指定的特定字符,您可以使用从 v0.6.0 开始与 dompdf 捆绑的 DejaVu 字体(例如 DejaVu Sans)。

尝试以下操作:

<!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>&#9744;</p>
  <p>☐</p>
</body>
</html>

有关如何安装字体的信息,请参阅此处: