Stirling-PDF/public/functions/mergePDFs.js
Felix Kaspar 26cdb1d04f Removed duplicate code of node backend
Frontend traverser needs to be updated
2023-10-22 00:55:28 +02:00

13 lines
436 B
JavaScript

export const mergePDFs = async (snapshots, PDFLib) => {
const mergedPdf = await PDFLib.PDFDocument.create();
for (let i = 0; i < snapshots.length; i++) {
const pdfToMerge = await PDFLib.PDFDocument.load(snapshots[i]);
const copiedPages = await mergedPdf.copyPages(pdfToMerge, pdfToMerge.getPageIndices());
copiedPages.forEach((page) => mergedPdf.addPage(page));
}
return mergedPdf.save();
};