diff --git a/types/pdfjs-dist/index.d.ts b/types/pdfjs-dist/index.d.ts index 029c4308e9..798629c704 100644 --- a/types/pdfjs-dist/index.d.ts +++ b/types/pdfjs-dist/index.d.ts @@ -44,11 +44,203 @@ interface PDFMetadata { has(name: string): boolean; } +interface PDFDataRangeTransportListener { + (loaded: number, total: number): void +} + +declare enum VerbosityLevel { + ERRORS = 0, + WARNINGS= 1, + INFOS= 5, +} + +declare class PDFDataRangeTransport { + constructor(length: number, initialData: Uint8Array|BufferSource, progressiveDone?: boolean); + addRangeListener(listener: PDFDataRangeTransportListener):void + addProgressListener(listener: PDFDataRangeTransportListener): void + addProgressiveReadListener(listener: PDFDataRangeTransportListener): void + addProgressiveDoneListener(listener: PDFDataRangeTransportListener): void + onDataRange(begin: number, chunk: unknown): void + onDataProgress(loaded: number, total: number): void + onDataProgressiveRead(chunk: unknown): void + onDataProgressiveDone(): void + transportReady() : void + requestDataRange(begin: number, end: number): void + abort(): void +} + +interface PDFWorkerParameters { + name?: string + port?: any + verbosity?: VerbosityLevel +} + +declare class PDFWorker { + constructor(params?: PDFWorkerParameters) + readonly promise: Promise + readonly port: any |null + readonly messageHandler: unknown | null + destroy(): void + static fromPort(params?: PDFWorkerParameters): PDFWorker + static getWorkerSrc(): string +} +declare enum CMapCompressionType { + NONE = 0, + BINARY= 1, + STREAM= 2, + } +interface CMapReaderFactory { + new (params: {baseUrl: string, isCompressed: boolean}): CMapReader +} +interface CMapReader { + fetch(params: {name: string}): Promise<{ + cMapData: any, + compressionType: CMapCompressionType + }> +} interface PDFSource { + /** The URL of the PDF. */ url?: string; - data?: Uint8Array; - httpHeaders?: any; + /** + * Binary PDF data. Use typed arrays + * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded, + * use atob() to convert it to a binary string first. + */ + data?: Uint8Array | BufferSource | string; + /** + * Basic authentication headers. + */ + httpHeaders?: { + [key: string]: string + }; + /** + * For decrypting password-protected PDFs. + */ password?: string; + /** + * Indicates whether or not cross-site + * Access-Control requests should be made using credentials such as cookies + * or authorization headers. The default is false. + */ + withCredentials?: boolean; + /* + * A typed array with the first portion or + * all of the pdf data. Used by the extension since some data is already + * loaded before the switch to range requests. */ + initialData?: Uint8Array | BufferSource; + /* + * The PDF file length. It's used for progress + * reports and range requests operations. + */ + length?: number; + /** range */ + range?: PDFDataRangeTransport; + /** + * Optional parameter to specify + * maximum number of bytes fetched per range request. The default value is + * 2^16 = 65536. */ + rangeChunkSize?: number + /** + * The worker that will be used for + * the loading and parsing of the PDF data. + */ + worker?: PDFWorker; + /** + * Controls the logging level; the + * constants from {VerbosityLevel} should be used. + */ + verbosity?: number; + /** + * The base URL of the document, + * used when attempting to recover valid absolute URLs for annotations, and + * outline items, that (incorrectly) only specify relative URLs. + */ + docBaseUrl?: string; + /** + * Strategy for + * decoding certain (simple) JPEG images in the browser. This is useful for + * environments without DOM image and canvas support, such as e.g. Node.js. + * Valid values are 'decode', 'display' or 'none'; where 'decode' is intended + * for browsers with full image/canvas support, 'display' for environments + * with limited image support through stubs (useful for SVG conversion), + * and 'none' where JPEG images will be decoded entirely by PDF.js. + * The default value is 'decode'. + */ + nativeImageDecoderSupport?: "decode"|"display"|"none" + /** + * The URL where the predefined + * Adobe CMaps are located. Include trailing slash. */ + cMapUrl?: string + /** + * Specifies if the Adobe CMaps are + * binary packed. */ + cMapPacked?: boolean + /** + * The factory that will be + * used when reading built-in CMap files. Providing a custom factory is useful + * for environments without `XMLHttpRequest` support, such as e.g. Node.js. + * The default value is {DOMCMapReaderFactory}. + */ + CMapReaderFactory?: any + /** + * Reject certain promises, e.g. + * `getOperatorList`, `getTextContent`, and `RenderTask`, when the associated + * PDF data cannot be successfully parsed, instead of attempting to recover + * whatever possible of the data. The default value is `false`. + */ + stopAtErrors?: boolean + /** + * The maximum allowed image size + * in total pixels, i.e. width * height. Images above this value will not be + * rendered. Use -1 for no limit, which is also the default value. + */ + maxImageSize?: number + /** + * Determines if we can eval + * strings as JS. Primarily used to improve performance of font rendering, + * and when parsing PDF functions. The default value is `true`. + */ + isEvalSupported?: boolean + /** + * By default fonts are + * converted to OpenType fonts and loaded via font face rules. If disabled, + * fonts will be rendered using a built-in font renderer that constructs the + * glyphs with primitive path commands. The default value is `false`. + */ + disableFontFace?: boolean + /** + * Disable range request loading + * of PDF files. When enabled, and if the server supports partial content + * requests, then the PDF will be fetched in chunks. + * The default value is `false`. + */ + disableRange?: boolean + /** + * Disable streaming of PDF file + * data. By default PDF.js attempts to load PDFs in chunks. + * The default value is `false`. + */ + disableStream?: boolean + /** + * Disable pre-fetching of PDF + * file data. When range requests are enabled PDF.js will automatically keep + * fetching more data even if it isn't needed to display the current page. + * The default value is `false`. + * NOTE: It is also necessary to disable streaming, see above, + * in order for disabling of pre-fetching to work correctly. + */ + disableAutoFetch?: boolean + /** + * Disable the use of + * `URL.createObjectURL`, for compatibility with older browsers. + * The default value is `false`. + */ + disableCreateObjectURL?: boolean + /** + * Enables special hooks for debugging + * PDF.js (see `web/debugger.js`). The default value is `false`. + */ + pdfBug?: boolean } interface PDFProgressData { @@ -461,22 +653,22 @@ declare const Util: PDFJSUtilStatic; * @return A promise that is resolved with PDFDocumentProxy object. **/ declare function getDocument( - source: string, - pdfDataRangeTransport?: any, + url: string, + pdfDataRangeTransport?: PDFDataRangeTransport, passwordCallback?: (fn: (password: string) => void, reason: string) => string, progressCallback?: (progressData: PDFProgressData) => void ): PDFLoadingTask; declare function getDocument( - source: Uint8Array, - pdfDataRangeTransport?: any, + data: Uint8Array | BufferSource, + pdfDataRangeTransport?: PDFDataRangeTransport, passwordCallback?: (fn: (password: string) => void, reason: string) => string, progressCallback?: (progressData: PDFProgressData) => void ): PDFLoadingTask; declare function getDocument( source: PDFSource, - pdfDataRangeTransport?: any, + pdfDataRangeTransport?: PDFDataRangeTransport, passwordCallback?: (fn: (password: string) => void, reason: string) => string, progressCallback?: (progressData: PDFProgressData) => void ): PDFLoadingTask;