Programmatically creating PDF from webpage

russtuck91 picture russtuck91 · May 29, 2013 · Viewed 9.4k times · Source

I have my resume online in an html page (www.mysite.com/resume.html). Every time I need a PDF version of it, I use Google Chrome's print dialog to save it as a PDF, which uses my print CSS stylesheet.

I want to be able to navigate to www.mysite.com/resume.pdf to always have an up to date PDF version without having to go through Google Chrome manually. Is there a way to programmatically and automatically create a resume.pdf from resume html? If I can write a script that runs once every 24 hours or something like that, that would be good.

Answer

tommypyatt picture tommypyatt · May 29, 2013

PhantomJS is perfect for this. It invokes an instance of WebKit from the command line which can then be used to output to file such as PDF.

PhantomJS:

http://phantomjs.org/

Specific instructions for exporting screen output to a file:

http://phantomjs.org/screen-capture.html

e.g.:

phantomjs rasterize.js 'http://www.example.com/resume.html' resume.pdf