mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-01-05 00:06:24 +01:00
Updated Page Functions
This commit is contained in:
parent
7bf100daff
commit
d7feec32dd
@ -6,7 +6,7 @@ import { Image } from 'image-js';
|
|||||||
import { getImagesOnPage } from "./getImagesOnPage.js";
|
import { getImagesOnPage } from "./getImagesOnPage.js";
|
||||||
|
|
||||||
export async function detectEmptyPages(file: PdfFile, whiteThreashold: number): Promise<number[]> {
|
export async function detectEmptyPages(file: PdfFile, whiteThreashold: number): Promise<number[]> {
|
||||||
const pdfDoc = await file.getAsPdfJs();
|
const pdfDoc = await file.pdfjsDocuemnt;
|
||||||
|
|
||||||
const emptyPages: number[] = [];
|
const emptyPages: number[] = [];
|
||||||
for (let i = 1; i <= pdfDoc.numPages; i++) {
|
for (let i = 1; i <= pdfDoc.numPages; i++) {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
import { PDFPageProxy } from "pdfjs-dist/types/src/display/api.js";
|
import { PDFPageProxy } from "pdfjs-dist/types/src/display/api.js";
|
||||||
import * as PDFJS from 'pdfjs-dist';
|
import * as PDFJS from 'pdfjs-dist';
|
||||||
|
|
||||||
|
// TODO: Type Return Value
|
||||||
export async function getImagesOnPage(page: PDFPageProxy) {
|
export async function getImagesOnPage(page: PDFPageProxy) {
|
||||||
const ops = await page.getOperatorList();
|
const ops = await page.getOperatorList();
|
||||||
const images: any = [];
|
const images: any = [];
|
||||||
|
@ -15,5 +15,5 @@ export async function mergePDFs(params: MergeParamsType): Promise<PdfFile> {
|
|||||||
copiedPages.forEach((page) => mergedPdf.addPage(page));
|
copiedPages.forEach((page) => mergedPdf.addPage(page));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new PdfFile(params.files.map(f => ), mergedPdf, params.files[0].filename);
|
return new PdfFile("mergedPDF", mergedPdf);
|
||||||
};
|
};
|
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import { PDFPage } from 'pdf-lib';
|
import { PDFPage } from 'pdf-lib';
|
||||||
import { PdfFile, fromPdfLib } from '../wrappers/PdfFile';
|
import { PdfFile } from '../wrappers/PdfFile';
|
||||||
|
|
||||||
export type ScaleContentParamsType = {
|
export type ScaleContentParamsType = {
|
||||||
file: PdfFile;
|
file: PdfFile;
|
||||||
@ -10,7 +10,7 @@ export type ScaleContentParamsType = {
|
|||||||
export async function scaleContent(params: ScaleContentParamsType): Promise<PdfFile> {
|
export async function scaleContent(params: ScaleContentParamsType): Promise<PdfFile> {
|
||||||
const { file, scaleFactor } = params;
|
const { file, scaleFactor } = params;
|
||||||
|
|
||||||
const pdfDoc = await file.getAsPdfLib();
|
const pdfDoc = await file.pdflibDocument;
|
||||||
const pages = pdfDoc.getPages();
|
const pages = pdfDoc.getPages();
|
||||||
|
|
||||||
if (Array.isArray(scaleFactor)) {
|
if (Array.isArray(scaleFactor)) {
|
||||||
@ -24,7 +24,7 @@ export async function scaleContent(params: ScaleContentParamsType): Promise<PdfF
|
|||||||
pages.forEach(page => scalePage(page, scaleFactor));
|
pages.forEach(page => scalePage(page, scaleFactor));
|
||||||
}
|
}
|
||||||
|
|
||||||
return fromPdfLib(pdfDoc, file.filename);
|
return file;
|
||||||
};
|
};
|
||||||
|
|
||||||
function scalePage(page: PDFPage, scaleFactor: number) {
|
function scalePage(page: PDFPage, scaleFactor: number) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import { PDFPage } from 'pdf-lib';
|
import { PDFPage } from 'pdf-lib';
|
||||||
import { PdfFile, fromPdfLib } from '../wrappers/PdfFile';
|
import { PdfFile } from '../wrappers/PdfFile';
|
||||||
|
|
||||||
export type ScalePageParamsType = {
|
export type ScalePageParamsType = {
|
||||||
file: PdfFile;
|
file: PdfFile;
|
||||||
@ -10,7 +10,7 @@ export type ScalePageParamsType = {
|
|||||||
export async function scalePage(params: ScalePageParamsType): Promise<PdfFile> {
|
export async function scalePage(params: ScalePageParamsType): Promise<PdfFile> {
|
||||||
const { file, pageSize } = params;
|
const { file, pageSize } = params;
|
||||||
|
|
||||||
const pdfDoc = await file.getAsPdfLib();
|
const pdfDoc = await file.pdflibDocument;
|
||||||
const pages = pdfDoc.getPages();
|
const pages = pdfDoc.getPages();
|
||||||
|
|
||||||
if (Array.isArray(pageSize)) {
|
if (Array.isArray(pageSize)) {
|
||||||
@ -24,7 +24,7 @@ export async function scalePage(params: ScalePageParamsType): Promise<PdfFile> {
|
|||||||
pages.forEach(page => resize(page, pageSize));
|
pages.forEach(page => resize(page, pageSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
return fromPdfLib(pdfDoc, file.filename);
|
return file;
|
||||||
};
|
};
|
||||||
|
|
||||||
function resize(page: PDFPage, newSize: {width?:number,height?:number}) {
|
function resize(page: PDFPage, newSize: {width?:number,height?:number}) {
|
||||||
|
@ -37,7 +37,7 @@ export async function splitOn(params: SplitOnParamsType) {
|
|||||||
console.log("Split At Pages: ", splitAtPages);
|
console.log("Split At Pages: ", splitAtPages);
|
||||||
|
|
||||||
// Remove detected Pages & Split
|
// Remove detected Pages & Split
|
||||||
const pdfDoc = await file.getAsPdfLib();
|
const pdfDoc = await file.pdflibDocument;
|
||||||
const numberOfPages = pdfDoc.getPageCount();
|
const numberOfPages = pdfDoc.getPageCount();
|
||||||
|
|
||||||
let pagesArray: number[] = [];
|
let pagesArray: number[] = [];
|
||||||
@ -66,7 +66,7 @@ export async function splitOn(params: SplitOnParamsType) {
|
|||||||
return subDocuments;
|
return subDocuments;
|
||||||
|
|
||||||
async function getPagesWithQRCode(file: PdfFile) {
|
async function getPagesWithQRCode(file: PdfFile) {
|
||||||
const pdfDoc = await file.getAsPdfJs();
|
const pdfDoc = await file.pdfjsDocuemnt;
|
||||||
|
|
||||||
const pagesWithQR: number[] = [];
|
const pagesWithQR: number[] = [];
|
||||||
for (let i = 0; i < pdfDoc.numPages; i++) {
|
for (let i = 0; i < pdfDoc.numPages; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user