UNPKG

afpp

Version:

another f*cking pdf parser

45 lines (44 loc) 1.93 kB
export declare enum PROCESSING_TYPE { IMAGE = "IMAGE", MIXED = "MIXED", TEXT = "TEXT" } import { Canvas, CanvasRenderingContext2D } from '@napi-rs/canvas'; export interface AfppParseOptions { /** * Concurrency level for page processing. Defaults to 1. * Higher values may improve performance but increase memory usage. * @default 1 */ concurrency?: number; /** * Image encoding format when rendering non-text pages. Defaults to 'png'. * Supported formats: 'avif', 'jpeg', 'png', 'webp'. * @default 'png' */ imageEncoding?: ImageEncoding; /** * Password for encrypted pdf files. */ password?: string; /** * Scale of a page if content is not text. Defaults to 2.0. * Higher values increase image resolution but also memory usage. * @default 2.0 */ scale?: number; } export interface CanvasAndContext { canvas: Canvas; context: CanvasRenderingContext2D; } export type ImageEncoding = 'avif' | 'jpeg' | 'png' | 'webp'; export type PageProcessor<T> = (content: Buffer | string, pageNumber: number, pageCount: number) => Promise<T> | T; export interface PdfCanvasFactory { create(width: number, height: number): CanvasAndContext; destroy(canvasAndContext: CanvasAndContext): void; reset(canvasAndContext: CanvasAndContext, width: number, height: number): void; } export declare function parsePdfFile(type: PROCESSING_TYPE.IMAGE, input: Buffer | string | Uint8Array | URL, options?: AfppParseOptions, callback?: undefined): Promise<Buffer[]>; export declare function parsePdfFile(type: PROCESSING_TYPE.TEXT, input: Buffer | string | Uint8Array | URL, options?: AfppParseOptions, callback?: undefined): Promise<string[]>; export declare function parsePdfFile<T>(type: PROCESSING_TYPE.MIXED, input: Buffer | string | Uint8Array | URL, options: AfppParseOptions, callback: PageProcessor<T>): Promise<T[]>;