Cutycapt、wkhtmltopdf、wkhtmltoimage、phantomjs 无法正确显示字符

发布于 2024-12-13 12:37:07 字数 573 浏览 7 评论 0原文

他们显示的唯一字符是英文字符。

打印页面的布局是应该的,但唯一错误的是英语(罗马)以外的任何脚本中的字符被替换为方框。

我已经安装了 xvfb 和字体,但它仍然给我下面的错误

FreeFontPath: FPE "/usr/share/X11/fonts/misc" refcount is 2, should be 1; fixing.

现在,另一个错误也开始随机出现

FreeFontPath: FPE "/usr/share/X11/fonts/misc" refcount is 2, should be 1; fixing.
error opening security policy file /usr/lib64/xserver/SecurityPolicy

我花了一整天的时间试图修复这些错误,但我只是感到沮丧。

我正在运行 centos (Linux 2.6.18-274.7.1.el5xen #1 SMP Thu Oct 20 17:06:34 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux)

The only characters they are displaying are the English ones.

The layout of the printed page is as it should be, but the only thing that is wrong is the characters in any script other than english (roman) being replaced with boxes.

I have already installed xvfb and the fonts and it is still giving me the error below

FreeFontPath: FPE "/usr/share/X11/fonts/misc" refcount is 2, should be 1; fixing.

Now, another error has also started to come up randomly

FreeFontPath: FPE "/usr/share/X11/fonts/misc" refcount is 2, should be 1; fixing.
error opening security policy file /usr/lib64/xserver/SecurityPolicy

I have spent the whole day trying to fix these errors and I am just getting frustrated.

I am running centos (Linux 2.6.18-274.7.1.el5xen #1 SMP Thu Oct 20 17:06:34 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

溇涏 2024-12-20 12:37:07

此错误通常是由“缺少”字体引起的。 wkhtmltopdf 有时即使正确安装了字体也无法检测到字体(这在 *nix 系统上尤其普遍)。

我的解决方案是对字体进行 Base64 编码(您可以使用此工具)并将其包含在您的 CSS 中:

@font-face {
    font-family: 'OpenSans';
    src: url(data:font/truetype;charset=utf-8;base64,AAEAAAATAQA...
}

这保证了交叉平台兼容性,并且您不必在您使用的所有不同系统(开发、测试登台、生产等)上安装字体。

This error is often caused by "missing" fonts. wkhtmltopdf sometimes fails to detect fonts even when they are properly installed (this is especially prevalent on *nix systems).

My solution is to Base64 encode the font (you can use this tool) and include it in your CSS:

@font-face {
    font-family: 'OpenSans';
    src: url(data:font/truetype;charset=utf-8;base64,AAEAAAATAQA...
}

This guarantees cross-platform compatibility, and you don't have to instal fonts on all the different systems you're using (development, testing staging, production, etc).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文