3
votes

I have an HTML page that is converted to PDF via wkhtmltopdf. Everything works nice and dandy on my local machine, Arabic fonts, PDF conversion to them, new custom fonts. I used @font-face, locally stored fonts, and utf-8 encoding. No problems.

But up on the server, not only do (1) Arabic characters turn into black boxes, but (2) even not-that-extraordinary English fonts (like Georgia and Impact) stop working. The PDF is rendered in plain sans-serif. That is, if it renders at all. At times it doesn't even produce output. I've added @font-face rules on my CSS for the server but wkhtmltopdf doesn't seem to pick them up. I know these fonts and paths are fine on the server because the HTML page uses the same CSS style sheet and it renders perfectly.

If I do simple plain text without any odd fonts, wkhtmltopdf works fine.

Any ideas? Does this have to do with being on the server? My local machine has Windows 7, the server's running Linux.

1
Try to run the following commands on the server box if you can: mkfontdir, mkfontscale and fc-list. Do the fonts you need appear on the list that the last command produces?Joel Peltonen
Thanks - I tried those commands. Nope, Georgia and Impact aren't there on the server. Does this mean I need to upgrade the hosting plan to ask for more fonts? Wkhtmltopdf works fine on my local machine (Windows) even though the fonts aren't installed - because on my machine it responds to @font-face.user961627
I'm really surprised that you don't have Impact and Georgia on the win box, I thought they were pretty much universal :). I can't help you very much (which is why I didn't add an answer). There might be legal issues, but you could try adding the fonts on the server in your ~/.fonts folder and the running the mkfontdir etc commands again to see if that would help. Sorry to be of so little help! (I'd also test with a Lot of different CSS alternatives to see if those have any effect as they seem to be very problematic code.google.com/p/wkhtmltopdf/issues/detail?id=36&q=font)Joel Peltonen

1 Answers

1
votes

Problem solved. I did indeed need to upgrade my hosting plan so I could run the wkhtmltopdf static binary with X11. Although the Linux machine only has some Nimbus fonts on it, Arabic and other fonts are working fine for me by adding the font files and using @font-face css rules.

Additional note: to get Arabic text rendering properly using custom Arabic font files, I generated the required font files and css rules using FontSquirrel, with "No subsetting" under "Expert" rendering options.