Last active
August 15, 2019 15:35
-
-
Save colinrotherham/0c49caedf6288b402053a34082d0fafd to your computer and use it in GitHub Desktop.
Save to PDF from Puppeteer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import puppeteer from 'puppeteer'; | |
(async () => { | |
const browser = await puppeteer.launch(); | |
// Open new page | |
const page = await browser.newPage(); | |
// Go to website | |
await page.goto('http://www.red-phoenix-consulting.co.uk/', { | |
printBackground: true, | |
waitUntil: 'networkidle2', | |
}); | |
// Save to PDF | |
await page.pdf({ | |
path: 'home.pdf', | |
format: 'A4', | |
}); | |
// Close browser | |
await browser.close(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run:
Once Node.js 12 LTS is out, we can remove the optional
--experimental-modules
flag.