1
1
mirror of https://github.com/jxnblk/mdx-deck.git synced 2024-12-02 08:03:05 +03:00
mdx-deck/lib/pdf.js
2018-07-31 19:12:55 -04:00

32 lines
567 B
JavaScript

const path = require('path')
const puppeteer = require('puppeteer')
module.exports = async (opts = {}) => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
const {
outDir,
outFile,
port,
width = 1280,
height = 960,
} = opts
const filename = path.join(outDir, outFile)
await page.goto('http://localhost:' + port, {
waitUntil: 'networkidle2'
})
await page.pdf({
width,
height,
path: filename,
scale: 1,
printBackground: true
})
await browser.close()
return filename
}