UNPKG

@sylphide/pdf-actions

Version:

A NPM Package built on top of pdf-lib that provides functonalities like merge, rotate, split and many more...

18 lines (14 loc) 502 B
const { EmptyPDFDocument } = require("./createFileDoc"); const mergePDF = async (filesDocArray) => { if (filesDocArray.length < 2) { return filesDocArray[0] || null; } const mergedPdf = await EmptyPDFDocument(); for (let i = 0; i < filesDocArray.length; i++) { const fileDoc = filesDocArray[i]; const pages = await mergedPdf.copyPages(fileDoc, fileDoc.getPageIndices()); pages.forEach((page) => mergedPdf.addPage(page)); } return mergedPdf; }; module.exports = mergePDF;