2023-10-26 20:53:02 +02:00
|
|
|
|
2023-10-26 22:41:48 +02:00
|
|
|
import { PDFDocument } from 'pdf-lib';
|
2023-10-26 20:53:02 +02:00
|
|
|
|
|
|
|
export const mergePDFs = async (snapshots) => {
|
2023-10-17 02:14:06 +02:00
|
|
|
|
2023-10-26 22:41:48 +02:00
|
|
|
const mergedPdf = await PDFDocument.create();
|
2023-10-17 02:14:06 +02:00
|
|
|
|
|
|
|
for (let i = 0; i < snapshots.length; i++) {
|
2023-10-26 22:41:48 +02:00
|
|
|
const pdfToMerge = await PDFDocument.load(snapshots[i]);
|
2023-10-17 02:14:06 +02:00
|
|
|
|
|
|
|
const copiedPages = await mergedPdf.copyPages(pdfToMerge, pdfToMerge.getPageIndices());
|
|
|
|
copiedPages.forEach((page) => mergedPdf.addPage(page));
|
|
|
|
}
|
|
|
|
|
|
|
|
return mergedPdf.save();
|
|
|
|
};
|