mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2024-12-21 19:08:24 +01:00
16 lines
512 B
TypeScript
16 lines
512 B
TypeScript
|
|
import { PDFDocument } from 'pdf-lib';
|
|
|
|
export async function mergePDFs(snapshots: (string | Uint8Array | ArrayBuffer)[]): Promise<Uint8Array> {
|
|
|
|
const mergedPdf = await PDFDocument.create();
|
|
|
|
for (let i = 0; i < snapshots.length; i++) {
|
|
const pdfToMerge = await PDFDocument.load(snapshots[i]);
|
|
|
|
const copiedPages = await mergedPdf.copyPages(pdfToMerge, pdfToMerge.getPageIndices());
|
|
copiedPages.forEach((page) => mergedPdf.addPage(page));
|
|
}
|
|
|
|
return mergedPdf.save();
|
|
}; |