Smiley emoticon showed as weird character in PDF made with wkhtmltopdf

℡╲_俬逩灬. 提交于 2019-12-11 10:34:26

问题


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>

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?

The command I'm using is:

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


回答1:


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:

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>

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

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

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



来源:https://stackoverflow.com/questions/33901625/smiley-emoticon-showed-as-weird-character-in-pdf-made-with-wkhtmltopdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!