1const PDFMerger = require('pdf-merger-js');
2
3var merger = new PDFMerger();
4
5(async () => {
6 merger.add('pdf1.pdf'); //merge all pages. parameter is the path to file and filename.
7 merger.add('pdf2.pdf', [2]); // merge only page 2
8 merger.add('pdf2.pdf', [1, 3]); // merge the pages 1 and 3
9 merger.add('pdf2.pdf', '4, 7, 8'); // merge the pages 4, 7 and 8
10 merger.add('pdf3.pdf', '1 to 2'); //merge pages 1 to 2
11 merger.add('pdf3.pdf', '3-4'); //merge pages 3 to 4
12
13 await merger.save('merged.pdf'); //save under given name and reset the internal document
14})();