13

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.

russtuck91
  • 575
  • 2
  • 4
  • 16

3 Answers3

11

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
pimlottc
  • 3,066
  • 2
  • 29
  • 24
tommypyatt
  • 518
  • 3
  • 13
  • 1
    This won't be copying textual data into the PDF document. This seems more on lines of outputting screenshot to PDF, is that right? In that case, Accessibility of PDF would go for a toss. – sidnc86 Feb 20 '19 at 07:06
7

Chrome has started headless program.

With that, we can create a pdf. e.g. for windows navigate your commandline to

C:\Users\{{your_username}}\AppData\Local\Google\Chrome SxS\Application>

Then hit the command:

chrome --headless --print-to-pdf="d:\\{{path and file name}}.pdf" https://google.com
Vikas
  • 24,082
  • 37
  • 117
  • 159
  • 2
    I tried this out. But even in this answer's case, Accessibility tagging went for a toss. I supplied a URL of an Accessible website conforming to #WCAG norms but on converting, heading structure was lost. – sidnc86 Feb 20 '19 at 07:24
0

If you are looking to do this server-side via PHP might I recommend the Browsershot library which leverages the Puppeteer (NodeJS package) and Chrome / Chromium headless browser?

It works really well. Way easier to install and get going than wkhtmltopdf (which is another option that doesn't rely on a NodeJS package nor the Chrome/Chromium headless browser. Personally, I recommend Browsershot solution since wkhtmltopdf has some issues depending on the type of server (Linux distro and version) you're running. That is, the only reliable way to install wkhtmltopdf that I've found is to download and compile from source on the server that you're running and not through a package manager).

Also, if you happen to be needing a solution specifically while working on a Laravel project then there's a wrapper library for Browsershot available.

Check out this tutorial to get started.

racl101
  • 3,760
  • 4
  • 34
  • 33