From d7feec32dd5944d3bcddb97995b3f987cbe01071 Mon Sep 17 00:00:00 2001 From: Felix Kaspar Date: Tue, 14 Nov 2023 20:36:27 +0100 Subject: [PATCH] Updated Page Functions --- shared-operations/src/functions/common/detectEmptyPages.ts | 2 +- shared-operations/src/functions/common/getImagesOnPage.ts | 1 + shared-operations/src/functions/mergePDFs.ts | 2 +- shared-operations/src/functions/scaleContent.ts | 6 +++--- shared-operations/src/functions/scalePage.ts | 6 +++--- shared-operations/src/functions/splitOn.ts | 4 ++-- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/shared-operations/src/functions/common/detectEmptyPages.ts b/shared-operations/src/functions/common/detectEmptyPages.ts index 9db14d18..3497e0c5 100644 --- a/shared-operations/src/functions/common/detectEmptyPages.ts +++ b/shared-operations/src/functions/common/detectEmptyPages.ts @@ -6,7 +6,7 @@ import { Image } from 'image-js'; import { getImagesOnPage } from "./getImagesOnPage.js"; export async function detectEmptyPages(file: PdfFile, whiteThreashold: number): Promise { - const pdfDoc = await file.getAsPdfJs(); + const pdfDoc = await file.pdfjsDocuemnt; const emptyPages: number[] = []; for (let i = 1; i <= pdfDoc.numPages; i++) { diff --git a/shared-operations/src/functions/common/getImagesOnPage.ts b/shared-operations/src/functions/common/getImagesOnPage.ts index 10ce53c9..140fa28a 100644 --- a/shared-operations/src/functions/common/getImagesOnPage.ts +++ b/shared-operations/src/functions/common/getImagesOnPage.ts @@ -2,6 +2,7 @@ import { PDFPageProxy } from "pdfjs-dist/types/src/display/api.js"; import * as PDFJS from 'pdfjs-dist'; +// TODO: Type Return Value export async function getImagesOnPage(page: PDFPageProxy) { const ops = await page.getOperatorList(); const images: any = []; diff --git a/shared-operations/src/functions/mergePDFs.ts b/shared-operations/src/functions/mergePDFs.ts index 980e2bae..45e1f907 100644 --- a/shared-operations/src/functions/mergePDFs.ts +++ b/shared-operations/src/functions/mergePDFs.ts @@ -15,5 +15,5 @@ export async function mergePDFs(params: MergeParamsType): Promise { copiedPages.forEach((page) => mergedPdf.addPage(page)); } - return new PdfFile(params.files.map(f => ), mergedPdf, params.files[0].filename); + return new PdfFile("mergedPDF", mergedPdf); }; \ No newline at end of file diff --git a/shared-operations/src/functions/scaleContent.ts b/shared-operations/src/functions/scaleContent.ts index d3602815..251f90ca 100644 --- a/shared-operations/src/functions/scaleContent.ts +++ b/shared-operations/src/functions/scaleContent.ts @@ -1,6 +1,6 @@ import { PDFPage } from 'pdf-lib'; -import { PdfFile, fromPdfLib } from '../wrappers/PdfFile'; +import { PdfFile } from '../wrappers/PdfFile'; export type ScaleContentParamsType = { file: PdfFile; @@ -10,7 +10,7 @@ export type ScaleContentParamsType = { export async function scaleContent(params: ScaleContentParamsType): Promise { const { file, scaleFactor } = params; - const pdfDoc = await file.getAsPdfLib(); + const pdfDoc = await file.pdflibDocument; const pages = pdfDoc.getPages(); if (Array.isArray(scaleFactor)) { @@ -24,7 +24,7 @@ export async function scaleContent(params: ScaleContentParamsType): Promise scalePage(page, scaleFactor)); } - return fromPdfLib(pdfDoc, file.filename); + return file; }; function scalePage(page: PDFPage, scaleFactor: number) { diff --git a/shared-operations/src/functions/scalePage.ts b/shared-operations/src/functions/scalePage.ts index 093065c5..f47293a8 100644 --- a/shared-operations/src/functions/scalePage.ts +++ b/shared-operations/src/functions/scalePage.ts @@ -1,6 +1,6 @@ import { PDFPage } from 'pdf-lib'; -import { PdfFile, fromPdfLib } from '../wrappers/PdfFile'; +import { PdfFile } from '../wrappers/PdfFile'; export type ScalePageParamsType = { file: PdfFile; @@ -10,7 +10,7 @@ export type ScalePageParamsType = { export async function scalePage(params: ScalePageParamsType): Promise { const { file, pageSize } = params; - const pdfDoc = await file.getAsPdfLib(); + const pdfDoc = await file.pdflibDocument; const pages = pdfDoc.getPages(); if (Array.isArray(pageSize)) { @@ -24,7 +24,7 @@ export async function scalePage(params: ScalePageParamsType): Promise { pages.forEach(page => resize(page, pageSize)); } - return fromPdfLib(pdfDoc, file.filename); + return file; }; function resize(page: PDFPage, newSize: {width?:number,height?:number}) { diff --git a/shared-operations/src/functions/splitOn.ts b/shared-operations/src/functions/splitOn.ts index 9456b3b9..04e3ead9 100644 --- a/shared-operations/src/functions/splitOn.ts +++ b/shared-operations/src/functions/splitOn.ts @@ -37,7 +37,7 @@ export async function splitOn(params: SplitOnParamsType) { console.log("Split At Pages: ", splitAtPages); // Remove detected Pages & Split - const pdfDoc = await file.getAsPdfLib(); + const pdfDoc = await file.pdflibDocument; const numberOfPages = pdfDoc.getPageCount(); let pagesArray: number[] = []; @@ -66,7 +66,7 @@ export async function splitOn(params: SplitOnParamsType) { return subDocuments; async function getPagesWithQRCode(file: PdfFile) { - const pdfDoc = await file.getAsPdfJs(); + const pdfDoc = await file.pdfjsDocuemnt; const pagesWithQR: number[] = []; for (let i = 0; i < pdfDoc.numPages; i++) {