Created
July 11, 2019 07:52
-
-
Save dannyockilson/9f3f31b2dd6431d42b949f69d065f406 to your computer and use it in GitHub Desktop.
Puppeteer for html to pdf
This file contains hidden or 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
#!/bin/node | |
const puppeteer = require('puppeteer'); | |
const join = require('path').join; | |
const url = process.argv[2] || 'http://localhost:4000/sponsorship-opportunities'; | |
const filename = process.argv[3] || 'sponsor-pack.pdf'; | |
(async () => { | |
try { | |
const browser = await puppeteer.launch(); | |
const page = await browser.newPage(); | |
await page.goto(url); | |
await page.pdf({path: join(process.cwd(), filename), format: 'A4'}) | |
await browser.close(); | |
process.exit(0); | |
} catch(e) { | |
process.exit(1); | |
} | |
})() |
This file contains hidden or 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
{ | |
"name": "pdf-generator", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"puppeteer": "^1.17.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just stick them in a folder somewhere, run
npm i
thennode index.js https://url-to-turn-to-pdf name-of-output-file.pdf