mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2024-12-21 19:08:24 +01:00
More Types, Fixed isImageBlank
This commit is contained in:
parent
8f1f64f6c0
commit
921a8c431c
3
server-node/declarations/PdfcpuWrapper.d.ts
vendored
Normal file
3
server-node/declarations/PdfcpuWrapper.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
declare module '@stirling-pdf/shared-operations/src/wasm/pdfcpu/pdfcpu-wrapper-node.js' {
|
||||
export function oneToOne(wasmArray: string[], snapshot: Uint8Array): Promise<Uint8Array>;
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
|
||||
import { PdfFile } from '../../wrappers/PdfFile';
|
||||
import { PDFPageProxy } from "pdfjs-dist/types/src/display/api.js";
|
||||
import { Image } from 'image-js';
|
||||
import { Image, ImageKind } from 'image-js';
|
||||
|
||||
import { getImagesOnPage } from "./getImagesOnPage.js";
|
||||
import { getImagesOnPage, PDFJSImage } from "./getImagesOnPage.js";
|
||||
|
||||
export async function detectEmptyPages(file: PdfFile, whiteThreashold: number): Promise<number[]> {
|
||||
const pdfDoc = await file.pdfJsDocument;
|
||||
@ -43,8 +43,9 @@ async function areImagesBlank(page: PDFPageProxy, threshold: number): Promise<bo
|
||||
return true;
|
||||
}
|
||||
|
||||
async function isImageBlank(image: string | Uint8Array | ArrayBuffer, threshold: number): Promise<boolean> {
|
||||
var img = await Image.load(image);
|
||||
// TODO: Fix this function
|
||||
async function isImageBlank(image: PDFJSImage, threshold: number): Promise<boolean> {
|
||||
var img = new Image(image.width, image.height, image.data, { kind: "RGB" as ImageKind }); // TODO: Maybe respect image.kind and convert accordingly, needs to be tested with a pdf with alpha-image
|
||||
var grey = img.grey();
|
||||
var mean = grey.getMean();
|
||||
return mean[0] <= threshold;
|
||||
|
@ -8,7 +8,7 @@ export type PDFJSImage = {
|
||||
height: number;
|
||||
interpolate?: any;
|
||||
kind: number;
|
||||
data: Uint8Array;
|
||||
data: Uint8ClampedArray;
|
||||
};
|
||||
|
||||
export async function getImagesOnPage(page: PDFPageProxy): Promise<PDFJSImage[]> {
|
||||
|
@ -74,12 +74,12 @@ export async function oneToOne(wasmArray, snapshot) {
|
||||
}
|
||||
console.log("Nuping Done");
|
||||
|
||||
/* TODO:
|
||||
* Make this more elegant, this waits for the write to finish.
|
||||
* Maybe replace wasmfs with https://github.com/streamich/memfs
|
||||
*/
|
||||
await checkExistsWithTimeout("/output.pdf", 1000);
|
||||
console.log("Write started...");
|
||||
|
||||
|
||||
// TODO: Make this more elegant, this waits for the write to finish.
|
||||
// Maybe replace wasmfs with https://github.com/streamich/memfs
|
||||
let fileSize;
|
||||
while (true) {
|
||||
fileSize = fs.statSync("/output.pdf").size;
|
||||
|
Loading…
Reference in New Issue
Block a user