wkhtmltopdf and chinese characters
Asked Answered
P

2

7

Trying to generate a PDF with wkhtmltopdf but it gives me a lot of trouble displaying all the characters.

Some of characters work - e.g. when printing

  • "Invoice No (付款编号)" Chinese character no 1, 2 and 4 are correctly printed but character no 3 just displays an empty space in the PDF.
  • "Customer no (客户编号)" Chinese character no 1 and 4 are correctly displayed but character no 2 and 3 aren't displayed in the PDF.
  • "Total (总额)" none of the Chinese characters are displayed in the generated PDF.

I'm on a Ubuntu 14.04 desktop system with wkhtmltopdf version "wkhtmltopdf 0.12.1 (with patched qt)". I have installed the Chinese fonts and all the characters are correctly displayed in both gedit and Firefox on my system, but wkhtmltopdf only displayes about 75% of them.

My HTML document is made in with UTF-8 character set and is correctly displayed in Firefox and gedit. I have also tried to embed the font-face directly in the style section of the header using the

src: url(data:font/ttf;base64,AAEA....)
tag and wkhtmltopdf changes the font face as expected but the missing characters are still missing.

Any help is really really appreciated as I'm getting out of ideas.

Pianism answered 14/9, 2014 at 13:50 Comment(1)
Following the suggesting of George Michael - installing the fonts ttf-wqy-microhei, ttf-wqy-zenhei and running sudo fc-cache -f -v made the characters appear - thanks!!!Pianism
D
4

Did you install the Chinese, Japanese, and Korean Fonts that are mentioned in the Ubuntu Community Help Wiki?

Dampier answered 3/10, 2014 at 13:16 Comment(0)
P
1

Looking at the PDF generated on another System in detail, you can find out which font is used by wkhtmltopdf on that system and then locate the proper substitute. Dalibror Nasevic did the work for a large subset of asian fonts and described what he had to install on a CentOS (RedHat) based system:

Figuring out missing fonts for wkHTMLtoPDF

On a headless Debian-stretch-based system, according to Dalibror Nasevic I had to add fonts-droid-fallback, fonts-wqy-microhei and fonts-wqy-zenhei

In addition, following the recommendations from the Ubuntu Community Help Wiki, fonts-dejima-mincho, fonts-nanum-coding, fonts-takao, fonts-takao-gothic, fonts-takao-mincho might be worth giving a try.

Peculiarize answered 27/3, 2019 at 19:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.