问题
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>
😋
</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