UNPKG

pdfdataextract

Version:

Extract data from a pdf with pure javascript

57 lines (56 loc) 1.97 kB
import { PDFPageProxy } from 'pdfjs-dist/types/src/display/api'; import { OCRLang, Sort } from './types'; import { CanvasApi, CanvasApiConstructor } from './canvasapi'; import { OcrApi, OcrApiConstructor } from './ocrapi'; /** * pdf data information per page */ export declare class PdfPageData { private page; private readonly canvasApi; private readonly ocrApi; /** * @internal */ constructor(page: PDFPageProxy, canvasApi: CanvasApiConstructor<CanvasApi> | null, ocrApi: OcrApiConstructor<OcrApi> | null); /** * get the text of the page * * @param {boolean|Sort} [sort=false] - sort the text by text coordinates * @returns {Promise<string>} a promise that is resolved with a {string} with the extracted text of the page */ toText(sort?: boolean | Sort): Promise<string>; /** * recognizes the text from the image information of this pdf page * requires node-canvas/node-pureimage and tesseract.js as additional installation * * @param {OCRLang[]} langs - the language traineddata used for recognition * @returns {Promise<string>} the result as text */ ocr(langs: OCRLang[]): Promise<string>; /** * creates a canvas and renders * * @param {T} canvasApi - the canvas api that is used to create the canvas * @returns {Promise<T>} the canvas */ toCanvasApi<T extends CanvasApi>(canvasApi: CanvasApiConstructor<T>): Promise<T>; /** * converts to a jpeg image * * @param {number} [quality=0.8] - the quality of the image (0.0-1.0) * @returns {Promise<Buffer>} the jpeg image as a {Buffer} */ toJPEG(quality?: number): Promise<Buffer>; /** * converts to a png image * * @returns {Promise<Buffer>} the png image as a {Buffer} */ toPNG(): Promise<Buffer>; /** * close the page data * @returns {boolean} — if close was successfully */ close(): boolean; }