-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf-print.js
40 lines (39 loc) · 1.31 KB
/
pdf-print.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
29
30
31
32
33
34
35
36
37
38
39
40
const puppeteer = require("puppeteer");
const path = require("path");
const fs = require("fs");
const filePath = path.resolve(__dirname, './out/resume.pdf.html');
const filePathJP = path.resolve(__dirname, './out-ja/resume.pdf.html');
const cssPath = path.resolve(__dirname, './out/positive-pdf.css');
(async () => {
const htmlContent = fs.readFileSync(filePath);
const htmlContentJP = fs.readFileSync(filePathJP, { encoding: "utf8" });
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setContent(htmlContent.toString(), { waitUntil: ["domcontentloaded", "networkidle0"]})
await page.pdf({
path: "out/resume.pdf",
format: "A4",
printBackground: true,
displayHeaderFooter: false,
margin: {
top: "10mm",
left: "10mm",
right: "10mm",
bottom: "10mm"
}
});
await page.setContent(htmlContentJP.toString(), { waitUntil: ["domcontentloaded", "networkidle0"]})
await page.pdf({
path: "out-ja/resume-ja.pdf",
format: "A4",
printBackground: true,
displayHeaderFooter: false,
margin: {
top: "10mm",
left: "10mm",
right: "10mm",
bottom: "10mm"
}
});
await browser.close();
})();