mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-02-02 00:16:34 +01:00
Missed a few changes
This commit is contained in:
parent
576b0e02f6
commit
373c5e4c26
@ -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[] = [];
|
||||
|
@ -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();
|
||||
|
@ -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});
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user