mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2024-12-27 00:07:01 +01:00
26 lines
808 B
JavaScript
26 lines
808 B
JavaScript
|
import { createSubDocument } from "./extractPages.js";
|
||
|
|
||
|
const { PDFDocument, ParseSpeeds } = PDFLib;
|
||
|
|
||
|
export const splitPDF = async (snapshot, splitAfterPageArray) => {
|
||
|
const pdfDoc = await 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));
|
||
|
splitAfter = splitAfterPageArray.shift();
|
||
|
pagesArray = [];
|
||
|
}
|
||
|
pagesArray.push(i);
|
||
|
}
|
||
|
subDocuments.push(await createSubDocument(pdfDoc, pagesArray));
|
||
|
pagesArray = [];
|
||
|
|
||
|
return subDocuments;
|
||
|
};
|