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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user