Wednesday, July 29, 2009

Convert html to pdf: wkhtmltopdf

If you want to convert html to a pdf, there's no easier way to do it other than wkhtmltopdf!
I found some other interesting tid bits too:
Make sure you use the 0.8.3 or greater version, otherwise you may get an error:
"wkhtmltopdf: cannot connect to X server"
If you are using this from a web server, you need to use the proper headers for a PDf file. Even though that example is in PHP, the same applies to Perl as well (using some form of CGI (I use CGI::Fast))

print header(
-Content_type => 'application/pdf',
-Content_disposition => 'attachment; filename=report.pdf',

Note: Put in whatever name you like in place of "report.pdf"

Perhaps in the near future I'll have a nice examples site with all the code!

1 comment:

  1. Excellent site. Plenty of helpful info here.

    I'm sending it to some friends ans additionally sharing in delicious.
    And of course, thanks on your sweat!