paper-css icon indicating copy to clipboard operation
paper-css copied to clipboard

How to create PDF by Chrome headless

Open cognitom opened this issue 7 years ago • 1 comments

Chrome 59 has supported a new headless mode! :tada:

To try it, add a line below to your .bash_profile:

alias chrome="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"

Then, reload .bash_profile:

$ source ~/.bash_profile

and, run Chrome in headless mode:

$ chrome --headless --disable-gpu --virtual-time-budget=1000 --print-to-pdf=github.pdf https://github.com/
  • --disable-gpu: this is needed to avoid error
  • --print-to-pdf: set file to output
  • --virtual-time-budget: set time to wait after document ready (for SPA)

See more details here:

  • https://developers.google.com/web/updates/2017/04/headless-chrome
  • https://cs.chromium.org/chromium/src/headless/app/headless_shell_switches.cc

Good luck!

cognitom avatar Jun 07 '17 06:06 cognitom

How to delay pdf print if window load event is fired but page is not rendered yet?

petrovic-ivan avatar Mar 22 '19 22:03 petrovic-ivan