Use PhantomJS to Create PDFs from HTML
If you want to create PDF versions of your HTML use phantomjs PDF rendering. The rasterise.js example given in the PhantomJS works perfectly out of the box.
You can execute this on the command-line using:
phantomjs rasterize.js 'http://en.wikipedia.org/w/index.php?title=Jakarta&printable=yes' jakarta.pdf
You could integrate this call into an app by setting up a queue for calls to phantomjs. I use this in a couple of apps myself.
This way, you'll get pixel perfect PDF's of your HTML (along with the ability to use fancy webfonts), without having to learn a whole bunch of new syntax for, or install random modules for.
Written by Ian Wootten
Related protips
7 Responses
Thanks a lot
Does it keeps text selectable and links clickable?
Nice, that could come in very useful in a project I'm working on!
Doesn't rasterize just export an image? If that is the case, then this probably isn't an acceptable solution.
According to http://we-love-php.blogspot.com/2012/12/create-pdf-invoices-with-html5-and-phantomjs.html the text is selectable (don't know about links)
I tried the example and it's just a picture exported as pdf so no text can be selected
I am having a form template which gendrate the pdf using panthom js , How can i insert my logo on every single pdf page