Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zoutepopcorn/fa02175a6c877a38e1af1f56db83d4c7 to your computer and use it in GitHub Desktop.
Save zoutepopcorn/fa02175a6c877a38e1af1f56db83d4c7 to your computer and use it in GitHub Desktop.
//npm init -y
//npm install --save puppeteer
//usage: node script.js /path/to/input.html /path/to/output.pdf
//script.js
const puppeteer = require('puppeteer');
(async () => {
let fileinput = process.argv[2];
let fileoutput = process.argv[3];
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('file:///${fileinput}', {waitUntil: 'networkidle'});
await page.pdf({path: fileoutput, format: 'A4'});
browser.close();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment