-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
38 lines (35 loc) · 1.03 KB
/
Copy pathindex.js
File metadata and controls
38 lines (35 loc) · 1.03 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
const puppeteer = require('puppeteer');
const PDFMerger = require('pdf-merger-js');
const path = require("path");
const createPdf = async (pdfUrls, hostname) => {
try {
const browser = await puppeteer.launch({ args: ['--no-sandbox'] });
const page = await browser.newPage();
let files = [];
for (const url of pdfUrls) {
const pdfPath = `pdf/${url}.pdf`;
await page.goto(`${hostname}${url}`, {waitUntil: 'networkidle2', timeout: 0});
await page.pdf({
path: pdfPath,
format: 'Legal',
printBackground: true
});
files.push(pdfPath);
};
await browser.close();
return files;
} catch (error) {
console.log(error);
}
}
const mergePdf = async (pdfFiles, output) => {
const merger = new PDFMerger();
pdfFiles.forEach(pdf => {
merger.add(pdf);
});
await merger.save(output);
};
module.exports = {
createPdf,
mergePdf
}