2015-04-14

wkHTMLToPDF chinese character support on Linux based systems

This post will explain how to add support for Chinese characters in wkHTMLToPDF - the famous tool that converts HTML pages to PDF documents seamlessly. By default, if you have Chinese characters in your HTML page and convert the page to PDF with wkHTMLToPDF, nothing comes out (blanks replace chinese characters). I doubt this subject will be helpful to a lot of people around the world, but I might need to use this trick again in the future so why not blog about it?

The trick is to install Chinese character support on your OS and rebuild the cache. Under Ubuntu, I ran this command to install Chinese fonts:
apt-get install fonts-wqy-microhei ttf-wqy-microhei fonts-wqy-zenhei ttf-wqy-zenhei 
Note: package names might be different if you aren't under Ubuntu (try apt-cache search ... to search for packages)
Then, run this command to update the font cache:
fc-cache -f -v

After that, try generating a PDF again with wkHTMLToPDF: it works! Huge thanks to an anonymous user on StackOverflow for finding the solution.

Search This Blog