html2pdf

Super easy html to pdf in Rails

After trying PDFKit, htmldoc (PDF::HTMLDoc) and PDFmyURL, the winner is PDFmyURL.

WHY not PDFKit?

I dislike PDFKit for the installation issues and the stupid big amount of dependencies, because you need a lot of XOrg and Qt libs to make it work (it depends on wkhtmltopdf –the fugliest and random name, I know that it comes from Webkit html to pdf but it is ugly–), and I don’t want to play with xserver libraries on my server just for this. But I must say that PDFKit works and makes an amazing work, so if you don’t care about having X libs on your server you can try it.

WHY not htmldoc?

Ruby has an amazing wrapper for htmldoc, and it works really well, but It (htmldoc) can handle styles properly, so if you are planning to use it to ‘print’ one of your views, you must remake it without styles, or just be happy with the version without styles.

WHY PDFmyURL?

  1. Super easy to use.
  2. Fast and Free web service.
  3. If you need customization you can pay it for it.
  4. I just need 3 lines in a helper to use it https://gist.github.com/1230528
  5. It has a nice api
html2pdf server setup

I’m always forgetting to setup a working html2pdf binary on new server setups, here’s my reminder:

sudo apt-get install libqtcore4
# source: http://code.google.com/p/wkhtmltopdf/downloads/list
wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.11.0_rc1-static-amd64.tar.bz2
bunzip2 wkhtmltopdf-0.11.0_rc1-static-amd64.tar.bz2
tar -xvf wkhtmltopdf-0.11.0_rc1-static-amd64.tar
cp wkhtmltopdf-amd64 /usr/bin/wkhtmltopdf
ln /usr/bin/wkhtmltopdf /usr/bin/html2pdf