Made split pdf functions conform to the new design pattern.

This commit is contained in:
Saud Fatayerji
2023-11-17 15:52:44 +03:00
parent b4251b56fe
commit 4c8a85726d
5 changed files with 129 additions and 134 deletions

View File

@@ -0,0 +1,25 @@
import { PdfFile } from '../../wrappers/PdfFile.js';
import { getPages } from "./getPagesByIndex";
export async function splitPagesByIndex(file: PdfFile, splitAfterPageIndexes: number[]): Promise<PdfFile[]> {
const pdfLibDocument = await file.pdfLibDocument;
const numberOfPages = pdfLibDocument.getPages().length;
let pagesArray: number[] = [];
let splitAfter = splitAfterPageIndexes.shift();
const subDocuments: PdfFile[] = [];
for (let i = 0; i < numberOfPages; i++) {
if(splitAfter && i > splitAfter && pagesArray.length > 0) {
subDocuments.push(await getPages(file, pagesArray));
splitAfter = splitAfterPageIndexes.shift();
pagesArray = [];
}
pagesArray.push(i);
}
subDocuments.push(await getPages(file, pagesArray));
pagesArray = [];
return subDocuments;
};