Updated Page Functions

This commit is contained in:
Felix Kaspar 2023-11-14 20:36:27 +01:00
parent 7bf100daff
commit d7feec32dd
6 changed files with 11 additions and 10 deletions

View File

@ -6,7 +6,7 @@ import { Image } from 'image-js';
import { getImagesOnPage } from "./getImagesOnPage.js";
export async function detectEmptyPages(file: PdfFile, whiteThreashold: number): Promise<number[]> {
const pdfDoc = await file.getAsPdfJs();
const pdfDoc = await file.pdfjsDocuemnt;
const emptyPages: number[] = [];
for (let i = 1; i <= pdfDoc.numPages; i++) {

View File

@ -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 = [];

View File

@ -15,5 +15,5 @@ export async function mergePDFs(params: MergeParamsType): Promise<PdfFile> {
copiedPages.forEach((page) => mergedPdf.addPage(page));
}
return new PdfFile(params.files.map(f => ), mergedPdf, params.files[0].filename);
return new PdfFile("mergedPDF", mergedPdf);
};

View File

@ -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<PdfFile> {
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<PdfF
pages.forEach(page => scalePage(page, scaleFactor));
}
return fromPdfLib(pdfDoc, file.filename);
return file;
};
function scalePage(page: PDFPage, scaleFactor: number) {

View File

@ -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<PdfFile> {
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<PdfFile> {
pages.forEach(page => resize(page, pageSize));
}
return fromPdfLib(pdfDoc, file.filename);
return file;
};
function resize(page: PDFPage, newSize: {width?:number,height?:number}) {

View File

@ -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++) {