cognitom / cognitom/paper-css

How to create PDF by Chrome headless

Open
#13 1 comment 8 reactions 0 assignees View on GitHub
Dominant language
CSS
Stars
2.6k
Forks
335
PR merge metrics
No merged PRs in 30d

Description

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`:

```bash
$ source ~/.bash_profile
```

and, run Chrome in `headless` mode:

```bash
$ 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!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.