Files
Stirling-PDF/shared-operations/src/functions/common/getImagesOnPage.ts

28 lines
796 B
TypeScript
Raw Normal View History

2024-02-23 23:55:29 +01:00
import { PDFPageProxy } from "pdfjs-dist/types/src/display/api";
2023-11-16 01:06:20 +01:00
2024-01-04 20:17:54 -05:00
import * as PDFJS from "pdfjs-dist";
2024-05-13 20:46:04 +02:00
import { createCanvas } from "canvas";
2024-01-04 20:17:54 -05:00
export interface PDFJSImage {
2023-11-16 01:06:20 +01:00
width: number;
height: number;
interpolate?: any;
2023-11-17 15:58:44 +01:00
kind: number; // TODO: Document what this is, maybe hasAlpha?
2023-11-16 01:56:17 +01:00
data: Uint8ClampedArray;
2024-01-04 20:17:54 -05:00
}
2023-11-16 01:06:20 +01:00
export async function getImagesOnPage(page: PDFPageProxy): Promise<PDFJSImage[]> {
2023-10-27 02:56:13 +02:00
const ops = await page.getOperatorList();
2023-11-16 01:06:20 +01:00
const images: PDFJSImage[] = [];
2024-01-04 20:17:54 -05:00
for (let j=0; j < ops.fnArray.length; j++) {
if (ops.fnArray[j] == PDFJS.OPS.paintImageXObject) {
2024-05-13 20:46:04 +02:00
const image: PDFJSImage = page.objs.get(ops.argsArray[j][0])
console.log("Image: ", image);
2023-10-27 02:56:13 +02:00
images.push(image);
}
}
return images;
}