pdfdataextract
Version:
Extract data from a pdf with pure javascript
103 lines (102 loc) • 3.77 kB
TypeScript
import { CanvasApi, CanvasApiConstructor } from './canvasapi';
import { OcrApi, OcrApiConstructor } from './ocrapi';
import { PdfPageData } from './pdfpagedata';
import { VerbosityLevel, Permissions, Outline, MetadataInfo, Sort } from './types';
export type PdfDataExtractorOptions = {
/**
* password for a password-protected PDF
*
* @type {string}
*/
password?: string;
/**
* the logging level
*
* @type {VerbosityLevel}
*/
verbosity?: VerbosityLevel;
/**
* the canvas api used for rendering
*
* @type {CanvasApiConstructor}
*/
canvasApi?: CanvasApiConstructor<CanvasApi>;
/**
* the ocr api used for text detection
*
* @type {OcrApiConstructor}
*/
ocrApi?: OcrApiConstructor<OcrApi>;
};
/**
* the extractor for the data of the pdf
*/
export declare class PdfDataExtractor {
private readonly pdf_document;
private readonly canvasApi;
private readonly ocrApi;
private constructor();
/**
* get the extractor for the data
*
* @param {Uint8Array} data - the binary data file
* @param {PdfDataExtractorOptions} [options={}] - the options on how to open the data in the extractor
* @returns {Promise<PdfDataExtractor>} a promise that is resolved with a {PdfDataExtractor} object to pull the extracted data from
*/
static get(data: Uint8Array, options?: PdfDataExtractorOptions): Promise<PdfDataExtractor>;
/**
* get the fingerprint
*
* @returns {string | null} the fingerprint
*/
get fingerprint(): string | null;
/**
* get the number of pages
*
* @returns {string} the number of pages
*/
get pages(): number;
/**
* get the permission flags
*
* @returns {Promise<Permissions | null>} a promise that is resolved with a {Permissions | null} object that contains the permission flags for the PDF
*/
getPermissions(): Promise<Permissions | null>;
/**
* get the text
*
* @param {number|number[]|((pageNumber: number) => boolean)} [pages] - can either be the number of pages to be read,
* a number array with the specific pages (sorted by page number)
* or a filter function (return true to parse the page)
* @param {boolean|Sort} [sort=false] - sort the text by text coordinates
* @returns {Promise<string[]>} a promise that is resolved with a {string[]} array with the extracted text per page
*/
getText(pages?: number | number[] | ((pageNumber: number) => boolean), sort?: boolean | Sort): Promise<string[]>;
/**
* get the text
*
* @param {number|number[]|((pageNumber: number) => boolean)} [pages] - can either be the number of pages to be read,
* a number array with the specific pages (sorted by page number)
* or a filter function (return true to parse the page)
* @returns {Promise<string[]>} a promise that is resolved with a {string[]} array with the extracted text per page
*/
getPageData(pages?: number | number[] | ((pageNumber: number) => boolean)): Promise<(PdfPageData | null)[]>;
/**
* get the outline/bookmarks
*
* @returns {Promise<Outline[]>} a promise that is resolved with a {Outline[]} array with information from the tree outline
*/
getOutline(): Promise<Outline[] | null>;
/**
* get the metadata
*
* @returns {Promise<MetadataInfo | null>} a promise that is resolved with a {MetadataInfo | null} object with information from the metadata section
*/
getMetadata(): Promise<MetadataInfo | null>;
/**
* close the extractor
*
* @returns {Promise<void>} a promise that is resolved when destruction is completed
*/
close(): Promise<void>;
}