当我使用wkhtmltopdf时,Unicode字符会转换为损坏的符号

Fre*_*ind 3 java pdf unicode cjk wkhtmltopdf

我有包含一些Unicode字符的HTML,并以"UTF-8"保存到磁盘.我可以用less来显示它,所有字符显示得很好:

<h1>???Action?</h1>
<p>Play???????????????<code>Action</code>?????
Run Code Online (Sandbox Code Playgroud)

但是,当我使用"wkhtmltopdf"将其转换为PDF时,它会显示损坏的字符:

打破unicode

我的命令是:

wkhtmltopdf --encoding utf-8 book.html book.pdf
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题?

Fre*_*ind 11

最后我找到了原因:我的ubuntu服务器中没有unicode字体.

我从我的本地ubuntu上传一些truetype字体到服务器,一切正常.

freewind@freewind:/usr/share/fonts$ cd truetype/
freewind@freewind:/usr/share/fonts/truetype$ ls
arphic             ttf-dejavu               ttf-lao
freefont           ttf-devanagari-fonts     ttf-liberation
kochi              ttf-gujarati-fonts       ttf-malayalam-fonts
msttcorefonts      ttf-indic-fonts-core     ttf-oriya-fonts
openoffice         ttf-japanese-gothic.ttf  ttf-punjabi-fonts
sazanami           ttf-japanese-mincho.ttf  ttf-tamil-fonts
takao              ttf-kacst-one            ttf-telugu-fonts
thai               ttf-kannada-fonts        unfonts
ttf-bengali-fonts  ttf-khmeros-core         wqy
Run Code Online (Sandbox Code Playgroud)

我只是上传它们,它解决了这个问题,虽然我不知道哪个字体是关键.

  • 作为最后的手段,您可以使用具有大量字形的`Code 2000`字体 - 一种更完整的Unicode字体.http://en.wikipedia.org/wiki/Code2000 (2认同)