paper-css
paper-css copied to clipboard
How to create PDF by Chrome headless
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!
How to delay pdf print if window load event is fired but page is not rendered yet?