'wkhtmltopdf always using default sans-serif font

I'm using a Django wrapper with wkhtmltopdf however I'm having the problem that regardless of the fonts I use in my CSS it always just shows a default sans-serif font. It works locally and also works on the server when I just generate the HTML without converting it to the PDF.

This is how it shows on the server in the PDF and this is how it shows locally in the PDF. The font is a custom font base64 encoded, however it doesn't matter what font I use as none make a difference.

Is it something to do with the server setup?

Anyone have any ideas?

Thanks in advance.



Solution 1:[1]

What's the css you're applying to the text? wkhtmltopdf has some quirks, and apparently doesn't like fallbacks (link). I was observing something similar and finally got a serif font (closest I could get to Times New Roman w/o downloading) by doing

font-family: "serif";

Solution 2:[2]

wkhtmltopdf only includes fonts if it finds them in the local system in /usr/share/fonts

If you use fonts like font-family: 'Liberation Sans'; ,wkhtmltopdf will correctly include them in the PDF and render them as it should.

Solution 3:[3]

If someone is still looking for a solution (in the current version of wkHTMLtoPDF). The solutions above didn“t solve my problem.

For me the correct solution was to add an svg-font for each font (font-type). wkHTMLtoPDF takes at least the svg. In my case, it always took the fallback font (Arial). I just converted each font and added it to my font.scss.

I hope this helps.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sabliao
Solution 2 VasiliNovikov
Solution 3