mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2024-12-21 19:08:24 +01:00
26cdb1d04f
Frontend traverser needs to be updated
24 lines
790 B
JavaScript
24 lines
790 B
JavaScript
import { createSubDocument } from "./extractPages.js";
|
|
|
|
export async function splitPDF(snapshot, splitAfterPageArray, PDFLib) {
|
|
const pdfDoc = await PDFLib.PDFDocument.load(snapshot)
|
|
|
|
const numberOfPages = pdfDoc.getPages().length;
|
|
|
|
let pagesArray = [];
|
|
let splitAfter = splitAfterPageArray.shift();
|
|
const subDocuments = [];
|
|
|
|
for (let i = 0; i < numberOfPages; i++) {
|
|
if(i > splitAfter && pagesArray.length > 0) {
|
|
subDocuments.push(await createSubDocument(pdfDoc, pagesArray, PDFLib));
|
|
splitAfter = splitAfterPageArray.shift();
|
|
pagesArray = [];
|
|
}
|
|
pagesArray.push(i);
|
|
}
|
|
subDocuments.push(await createSubDocument(pdfDoc, pagesArray, PDFLib));
|
|
pagesArray = [];
|
|
|
|
return subDocuments;
|
|
}; |