Cutycapt, wkhtmltopdf, wkhtmltoimage, phantomjs not displaying characters properly

1.4k views Asked by At

The only characters they are displaying are the English ones.

The layout of the printed page is as it should be, but the only thing that is wrong is the characters in any script other than english (roman) being replaced with boxes.

I have already installed xvfb and the fonts and it is still giving me the error below

FreeFontPath: FPE "/usr/share/X11/fonts/misc" refcount is 2, should be 1; fixing.

Now, another error has also started to come up randomly

FreeFontPath: FPE "/usr/share/X11/fonts/misc" refcount is 2, should be 1; fixing.
error opening security policy file /usr/lib64/xserver/SecurityPolicy

I have spent the whole day trying to fix these errors and I am just getting frustrated.

I am running centos (Linux 2.6.18-274.7.1.el5xen #1 SMP Thu Oct 20 17:06:34 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux)

1

There are 1 answers

0
Arman H On

This error is often caused by "missing" fonts. wkhtmltopdf sometimes fails to detect fonts even when they are properly installed (this is especially prevalent on *nix systems).

My solution is to Base64 encode the font (you can use this tool) and include it in your CSS:

@font-face {
    font-family: 'OpenSans';
    src: url(data:font/truetype;charset=utf-8;base64,AAEAAAATAQA...
}

This guarantees cross-platform compatibility, and you don't have to instal fonts on all the different systems you're using (development, testing staging, production, etc).