5vmo1g
Last Updated: October 10, 2018
·
73.22K
· iwootten

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.

8 Responses
Add your response

7436

Thanks a lot

over 1 year ago ·
8823

Does it keeps text selectable and links clickable?

over 1 year ago ·
8871

Nice, that could come in very useful in a project I'm working on!

over 1 year ago ·
10045

Doesn't rasterize just export an image? If that is the case, then this probably isn't an acceptable solution.

over 1 year ago ·
10305

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)

over 1 year ago ·
12341

I tried the example and it's just a picture exported as pdf so no text can be selected

over 1 year ago ·
26255

I am having a form template which gendrate the pdf using panthom js , How can i insert my logo on every single pdf page

over 1 year ago ·
30223

Thank you for sharing this useful information, I will regularly follow your blog
http://slitherio-o.com

3 months ago ·