Made split pdf functions conform to the new design pattern.
This commit is contained in:
25
shared-operations/src/functions/common/splitPagesByIndex.ts
Normal file
25
shared-operations/src/functions/common/splitPagesByIndex.ts
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user