Ubuntu – Font letter spacing issue with PhantomJS/wkhtmltopdf on Ubuntu

fontsUbuntu

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

Best Answer

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)

Related Question