-
Notifications
You must be signed in to change notification settings - Fork 2
/
pdf.js
28 lines (22 loc) · 756 Bytes
/
pdf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const puppeteer = require("puppeteer");
const { getHtmlForSplitCards } = require("./html");
async function generatePdf(splitCards, pathAndFilename) {
// start PDF generation
const browser = await puppeteer.launch();
const page = await browser.newPage();
// get HTMl content for render
const html = await getHtmlForSplitCards(splitCards);
// Write the PDF
await page.setContent(html, { waitUntil: "domcontentloaded" });
const pdf = await page.pdf({
path: pathAndFilename,
margin: { top: "8", right: "0", bottom: "0", left: "0" },
printBackground: true,
displayHeaderFooter: false,
format: "A4",
landscape: true,
});
// Close the browser instance
await browser.close();
}
module.exports = { generatePdf };