I'm using PhantomJS/wkhtmltopdf on Ubuntu 12.04 LTS to convert HTML to PDF and get very strange letter spacing errors. For instance, the internal distance between es and xa seems very random and incorrect.

When I run the exact same code on OS X I don't get these problems which make me think the issue is related to Linux. Also, when I render to PNG it looks fine.

I'm using Microsoft Core Fonts and all fonts get the same kerning issue. For instance xa is always a problem, so I don't think it's a font problem either.

I've tried modifying ~/.fonts.conf according to the advice at those links but it makes no difference.

I'm quite stuck on ideas on how to solve this.

enter image description here

  • This might be helpful in reading through: groups.google.com/forum/#!topic/phantomjs/LBYIyBNGdkA
    – slm
    Jun 17, 2013 at 20:50
  • Thanks. I don't think there is anything there that could help me though. I just confirmed it is not a PhantomJS issue since I got the exact same output with wkhtmltopdf.
    – Anton
    Jun 17, 2013 at 21:54
  • I actually solved the issue by migrating to wkhtmltopdf. It may have been an invalid ~/.fonts.conf that confused wkhtmltopdf when I tested before. Now wkhtmltopdf works like a charm and PhantomJS still have the same issue.
    – Anton
    Jun 18, 2013 at 0:38
  • You're quite welcome.
    – slm
    Jun 18, 2013 at 1:02

1 Answer 1


My solution was to migrate to wkhtmltopdf.

It turns out that my problem happened under these circumstances:

  • Always with PhantomJS
  • With wkhtmltopdf when and invalid ~/.fonts.conf was present

A difference between PhantomJS and wkhtmltopdf is that the latter is using X server to do it's renderings, and this could of be the reason for the different behaviour I'm experiencing.

Using wkhtmltopdf now works fine whereas PhantomJS still gives funny font rendering. wkhtmltopdf seems to me like a more mature option when only html-to-pdf converting is needed so I will likely stick with it.

This looks better (different font, but the font itself was never the issue)

  • My understanding is that both WKHTML & PhantomJS use the same core QT Webkit for rendering. I'm not really a unix guy so thanks for following up and narrowing it down to X Server and the fonts.conf file; I'll research in that direction.
    – Chords
    Feb 4, 2014 at 15:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .