用wkhtmltopdf制成的PDF中显示为怪异字符的笑脸图释 [英] Smiley emoticon showed as weird character in PDF made with wkhtmltopdf

查看:402
本文介绍了用wkhtmltopdf制成的PDF中显示为怪异字符的笑脸图释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用wkhtmltopdf版本0.12.2.1 (with patched qt)将以下HTML转换为PDF:

I'm trying to convert the following HTML to a PDF using wkhtmltopdf, version 0.12.2.1 (with patched qt):

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
</head>

<body>
&#x1f60b;
</body>

</html>

HTML包含十六进制字符😋它在HTML中作为表情符号很好地显示,但在我的PDF中看起来像这样:

The HTML contains the hex character 😋 which shows up fine in the HTML as an emoticon, but in my PDF it looks like this:

为什么这样显示?我该如何解决?

Why is it displayed like that and how can I fix this?

我正在使用的命令是:

wkhtmltopdf /tmp/test.html /tmp/foo.pdf

推荐答案

对于现在遇到这个问题的人,我使用的是Windows二进制0.12.2.3(在Windows 10 1809上),并通过设置字体设法获得了wkhtmltopdf渲染图释家族可以识别字体的本地Windows字体家族:

For someone encountering this now, I'm using the Windows binary 0.12.2.3 (on Windows 10 1809) and managed to get wkhtmltopdf rendering emoticons by setting the font family to a local Windows font-family that recognizes fonts:

要进行快速测试,请将其插入HTML页面并重新生成PDF:

For a quick test, insert this into HTML page and regenerate your PDF:

<style>
    body {
        font-family: "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji",
            Times, Symbola, Aegyptus, Code2000, Code2001, Code2002, Musica, serif,
            LastResort;
        }
</style>

您现在应该可以看到表情符号,但是您可能必须将上述CSS定制为自己的应用.

You should see your emojis being rendered now, but you will likely have to tailor the above CSS to your own app.

要知道要使用哪种字体,我在此处转到了完整表情符号列表: https://unicode.org/emoji/charts/full-emoji-list.html

To know which font family to use, I went to Full Emoji List here: https://unicode.org/emoji/charts/full-emoji-list.html

然后我右键单击Chrome原生渲染的表情符号并复制字体系列.

Then I right clicked an emoji that was being natively rendered by Chrome and copied the font family.

这篇关于用wkhtmltopdf制成的PDF中显示为怪异字符的笑脸图释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆