-
Notifications
You must be signed in to change notification settings - Fork 0
/
mergePdf.js
23 lines (17 loc) · 870 Bytes
/
mergePdf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const PDFMerger = require('pdf-merger-js');
let merger = new PDFMerger();
const merge_pdfs = async (p1, p2) => {
await merger.add(p1); //merge all pages. parameter is the path to file and filename.
await merger.add(p2); // merge only page 2
let d = new Date().getTime()
// await merger.add('pdf2.pdf', [1, 3]); // merge the pages 1 and 3
// await merger.add('pdf2.pdf', '4, 7, 8'); // merge the pages 4, 7 and 8
// await merger.add('pdf3.pdf', '3 to 5'); //merge pages 3 to 5 (3,4,5)
// await merger.add('pdf3.pdf', '3-5'); //merge pages 3 to 5 (3,4,5)
await merger.save(`public/${d}.pdf`); //save under given name and reset the internal document
return d
// Export the merged PDF as a nodejs Buffer
// const mergedPdfBuffer = await merger.saveAsBuffer();
// fs.writeSync('merged.pdf', mergedPdfBuffer);
}
module.exports = {merge_pdfs}