Missed a few changes

This commit is contained in:
Saud Fatayerji 2023-11-16 02:26:45 +03:00
parent 576b0e02f6
commit 373c5e4c26
4 changed files with 14 additions and 18 deletions

View File

@ -41,7 +41,7 @@ export async function splitOn(params: SplitOnParamsType) {
console.log("File: ", file);
// Remove detected Pages & Split
const pdfDoc = await file.pdflibDocument;
const pdfDoc = await file.pdfLibDocument;
const numberOfPages = pdfDoc.getPageCount();
let pagesArray: number[] = [];
@ -71,7 +71,7 @@ export async function splitOn(params: SplitOnParamsType) {
async function getPagesWithQRCode(file: PdfFile) {
console.log("FileInQRPrev: ", file);
const pdfDoc = await file.pdfjsDocument;
const pdfDoc = await file.pdfJsDocument;
console.log("FileInQRAfter: ", file);
const pagesWithQR: number[] = [];

View File

@ -10,9 +10,9 @@ export type SplitPdfParamsType = {
export async function splitPDF(params: SplitPdfParamsType): Promise<PdfFile[]> {
const { file, splitAfterPageArray } = params;
const pdflibDocument = await file.pdfLibDocument;
const pdfLibDocument = await file.pdfLibDocument;
const numberOfPages = pdflibDocument.getPages().length;
const numberOfPages = pdfLibDocument.getPages().length;
let pagesArray: number[] = [];
let splitAfter = splitAfterPageArray.shift();

View File

@ -21,9 +21,9 @@ export async function sortPagesWithPreset(params: SortPagesWithPresetParamsType)
throw new Error("Operation not supported");
}
const pdflibDocument = await file.pdflibDocument;
const pdfLibDocument = await file.pdfLibDocument;
const pageCount = pdflibDocument.getPageCount();
const pageCount = pdfLibDocument.getPageCount();
const sortIndecies = sortFunction(pageCount);
return selectPages({file: file, pagesToExtractArray: sortIndecies});
}
@ -36,9 +36,9 @@ export type RearrangePagesParamsType = {
export async function rearrangePages(params: RearrangePagesParamsType): Promise<PdfFile> {
const { file, fancyPageSelector } = params;
const pdflibDocument = await file.pdflibDocument;
const pdfLibDocument = await file.pdfLibDocument;
const pagesToExtractArray = parseFancyPageSelector(fancyPageSelector, pdflibDocument.getPageCount());
const pagesToExtractArray = parseFancyPageSelector(fancyPageSelector, pdfLibDocument.getPageCount());
const newDocument = selectPages({file: file, pagesToExtractArray});
return newDocument;
};
@ -50,16 +50,16 @@ export type SelectPagesParamsType = {
export async function selectPages(params: SelectPagesParamsType): Promise<PdfFile> {
const { file, pagesToExtractArray } = params;
const pdflibDocument = await file.pdflibDocument;
const pdfLibDocument = await file.pdfLibDocument;
const subDocument = await PDFDocument.create();
// Check that array max number is not larger pdf pages number
if(Math.max(...pagesToExtractArray) >= pdflibDocument.getPageCount()) {
throw new Error(`The PDF document only has ${pdflibDocument.getPageCount()} pages and you tried to extract page ${Math.max(...pagesToExtractArray)}`);
if(Math.max(...pagesToExtractArray) >= pdfLibDocument.getPageCount()) {
throw new Error(`The PDF document only has ${pdfLibDocument.getPageCount()} pages and you tried to extract page ${Math.max(...pagesToExtractArray)}`);
}
const copiedPages = await subDocument.copyPages(pdflibDocument, pagesToExtractArray);
const copiedPages = await subDocument.copyPages(pdfLibDocument, pagesToExtractArray);
for (let i = 0; i < copiedPages.length; i++) {
subDocument.addPage(copiedPages[i]);
@ -75,9 +75,9 @@ export type RemovePagesParamsType = {
export async function removePages(params: RemovePagesParamsType): Promise<PdfFile> {
const { file, pagesToRemoveArray } = params;
const pdflibDocument = await file.pdflibDocument;
const pdfLibDocument = await file.pdfLibDocument;
const pagesToExtractArray = invertSelection(pagesToRemoveArray, pdflibDocument.getPageIndices())
const pagesToExtractArray = invertSelection(pagesToRemoveArray, pdfLibDocument.getPageIndices())
return selectPages({file: file, pagesToExtractArray});
}

View File

@ -62,22 +62,18 @@ export async function * traverseOperations(operations: Action[], input: PdfFile[
case "impose":
yield* nToN(input, action, async (input) => {
const newPdf = await Operations.impose({file: input, nup: action.values["nup"], format: action.values["format"]});
newPdf.filename += "_imposed";
console.log("newPDF: ", newPdf);
return newPdf;
});
break;
case "merge":
yield* nToOne(input, action, async (inputs) => {
const newPdf = await Operations.mergePDFs({files: inputs});
newPdf.filename = inputs.map(input => input.filename).join("_and_") + "_merged";
return newPdf;
});
break;
case "rotate":
yield* nToN(input, action, async (input) => {
const newPdf = await Operations.rotatePages({file: input, rotation: action.values["rotation"]});
newPdf.filename += "_turned";
return newPdf;
});
break;