-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpdf.js
More file actions
56 lines (50 loc) · 1.34 KB
/
pdf.js
File metadata and controls
56 lines (50 loc) · 1.34 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const puppeteer = require('puppeteer');
const MARGIN = '0.5cm';
const isCI = (process.argv[2] || '').toLowerCase() === 'ci';
const urlSuffix = isCI ? '9000/resume' : '8000';
const CITimeout = 3000;
const main = async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
try {
await page.goto(`http://localhost:${urlSuffix}`, {waitUntil: ['domcontentloaded', 'networkidle2']});
await page.pdf({
path: 'Maciej Sawicki - Resume.pdf',
format: 'A4',
printBackground: true,
margin: {
top: MARGIN,
right: MARGIN,
bottom: MARGIN,
left: MARGIN,
},
displayHeaderFooter: true,
headerTemplate: `<div></div>`,
// fixme: footer doesn't work when margin is 0.5 cm :/ It worked for 1cm though
// footerTemplate: footerTemplate,
});
} finally {
await browser.close();
}
};
const mainInvoker = () =>
main()
.catch(error => {
console.error(error)
process.exit(1)
})
if (isCI) {
setTimeout(() => {
mainInvoker()
}, CITimeout)
} else {
mainInvoker()
}
// language=HTML
const footerTemplate = `
<div style="font-size: 8px; display: flex; align-items: center; margin-left: auto; margin-right: ${MARGIN};">
<span class="pageNumber"></span>
<span>/</span>
<span class="totalPages"></span>
</div>
`;