Solved type issues in traverseOperations etc. Changed functions to take a object single parameter. Condensed endpoints into a function call

This commit is contained in:
Saud Fatayerji
2023-11-14 03:26:42 +03:00
parent 77274e6117
commit 9956367384
18 changed files with 377 additions and 260 deletions

View File

@@ -2,7 +2,14 @@
import { selectPages } from "./subDocumentFunctions";
import { PdfFile } from '../wrappers/PdfFile';
export async function splitPDF(file: PdfFile, splitAfterPageArray: number[]): Promise<PdfFile[]> {
export type SplitPdfParamsType = {
file: PdfFile;
splitAfterPageArray: number[];
}
export async function splitPDF(params: SplitPdfParamsType): Promise<PdfFile[]> {
const { file, splitAfterPageArray } = params;
const byteFile = await file.convertToPdfLibFile();
if (!byteFile?.pdfLib) return [];
@@ -14,13 +21,13 @@ export async function splitPDF(file: PdfFile, splitAfterPageArray: number[]): Pr
for (let i = 0; i < numberOfPages; i++) {
if(splitAfter && i > splitAfter && pagesArray.length > 0) {
subDocuments.push(await selectPages(byteFile, pagesArray));
subDocuments.push(await selectPages({file:byteFile, pagesToExtractArray:pagesArray}));
splitAfter = splitAfterPageArray.shift();
pagesArray = [];
}
pagesArray.push(i);
}
subDocuments.push(await selectPages(byteFile, pagesArray));
subDocuments.push(await selectPages({file:byteFile, pagesToExtractArray:pagesArray}));
pagesArray = [];
return subDocuments;