import { Writable } from 'stream'; import { Annotation, Manifest } from '@iiif/presentation-3'; import Presentation2 from '@iiif/presentation-2'; type LogLevel = 'debug' | 'info' | 'warn' | 'error'; interface Logger { setLevel(level: LogLevel): void; debug(message: string, ...args: any[]): void; info(message: string, ...args: any[]): void; warn(message: string, ...args: any[]): void; error(message: string, ...args: any[]): void; } /** Simple logger that simply outputs to the console */ declare class ConsoleLogger implements Logger { private level; constructor(level?: LogLevel); setLevel(level: LogLevel): void; debug(message: string, ...args: any[]): void; info(message: string, ...args: any[]): void; warn(message: string, ...args: any[]): void; error(message: string, ...args: any[]): void; } declare function setLogger(newLogger: Logger): void; /** Download the JSON data for a manifest, handling stuff like broken CORS implementations * and Content-Negotiation for IIIFv3 */ declare function fetchManifestJson(manifestUrl: string): Promise; /** Progress information for rendering a progress bar or similar UI elements. */ interface ProgressStatus { /** Message code that should be mapped to a human readable description in a UI. */ messageCode?: ProgressMessageCode; /** Expected total number of pages in the PDF */ totalPages: number; /** Number of pages that were submitted for writing */ pagesWritten: number; /** Number of bytes that were submitted for writing to the output stream */ bytesPushed: number; /** Number of bytes that were written to the output stream so far */ bytesWritten: number; /** Predicted size of the final file in bytes */ estimatedFileSize?: number; /** Write speed in bytes per second */ writeSpeed: number; /** Estimated time in seconds until PDF has finished generating */ remainingDuration: number; } /** Parameters for rendering a cover page, parsed from IIIF manifest. */ interface CoverPageParams { title: string; manifestUrl: string; thumbnail?: { url: string; iiifImageService?: string; }; provider?: { label: string; homepage?: string; logo?: string; }; requiredStatement?: { label: string; value: string; }; rights?: { text: string; url?: string; logo?: string; }; metadata?: Array<[string, string | Array]>; pdiiifVersion: string; } /** Options for converting a IIIF Manifest to a PDF. */ interface ConvertOptions { /** Callback to provide annotations for a given canvas identifier. * Should return either a `sc:AnnotationList` (IIIF2) or an `AnnotationPage` (IIIF3). */ fetchCanvasAnnotations?: (canvasId: string) => Promise | Array>; /** Pixels per inch to assume for the full resolution version of each canvas. If not set, the conversion will use an available IIIF Physical Dimensions service to calculate the page dimensions instead. */ ppi?: number; /** Set of canvas ids to include in PDF, or a predicate to filter canvas identifiers by. By default, all canvases are included in the PDF. */ filterCanvases?: readonly string[] | ((canvasId: string) => boolean); /** List of languages to use for metadata, page labels and table of contents, in descending order of preference. Will use the environment's locale settings by default. */ languagePreference?: readonly string[]; /** Restrict the image size to include in the PDF by downscaling by a fixed factor. * The value must be a number between 0.1 and 1. * Only works with Level 2 Image API services that allow arbitrary downscaling, the * conversion will not perform downscaling itself. * For Level 1 endpoints, the closest available lower width will be selected. */ scaleFactor?: number; /** Number of maximum concurrent IIIF Image API requests to be performed, defaults to 1 */ concurrency?: number; /** Callback that gets called whenever a page has finished, useful to render a progress bar. */ onProgress?: (status: ProgressStatus) => void; /** Callback that gets called with a notification when an error occurs during PDF generation * that does not cause the conversion to fail. */ onNotification?: (notification: ProgressNotification) => void; /** Controller that allows aborting the PDF generation. All pending downloads will be terminated. The caller is responsible for removing underlying partial files and/or other user signaling. */ abortController?: AbortController; /** Set PDF metadata, by default `Title` will be the manifest's label. */ metadata?: { CreationDate?: Date; Title?: string; Author?: string; Keywords?: string; }; /** Endpoint to contact for retrieving PDF data with one or more cover pages to insert before the canvas pages */ coverPageEndpoint?: string; /** Callback to call for retrieving PDF data with one or more cover pages to insert before the canvas pages */ coverPageCallback?: (params: CoverPageParams) => Promise; /** Generate the PDF in a way that the resulting file is also a valid * ZIP file that contains the manifest, all of the images and, if present, * the OCR files referenced in the manifest. */ polyglotZipPdf?: boolean; /** Base directory in the polyglot ZIP archive. If not set, all resource * directories will be to-level in the archive. */ polyglotZipBaseDir?: string; /** Custom loader callback that fetches the WASM binary for the `sax-wasm` * dependency (v2.2.4). By default, the dependency will be loaded from * `https://unpkg.com/sax-wasm/dist/sax-wasm.wasm`. Override if you want * to provide your own payload. Loader will not be called if {@link initialize} * from `ocr-parser` has been called before. */ saxWasmLoader?: () => Promise; } /** Parameters for size estimation */ interface EstimationParams { /** The manifest to determine the PDF size for */ manifest: string | Manifest | Presentation2.Manifest; /** Restrict the image size to include in the PDF by downscaling by a fixed factor. * The value must be a number between 0.1 and 1. * Only works with Level 2 Image API services that allow arbitrary downscaling, the * conversion will not perform downscaling itself. * For Level 1 endpoints, the closest available lower width will be selected. */ scaleFactor?: number; /** Set of canvas ids to include in PDF, or a predicate to filter canvas identifiers by. By default, all canvases are included in the PDF. */ filterCanvases?: readonly string[] | ((canvasId: string) => boolean); /** Number of canvses to sample for estimation, defaults to 8 */ numSamples?: number; /** Number of maximum concurrent IIIF Image API requests to be performed, defaults to 1 */ concurrency?: number; } type Estimation = { /** Estimated size of the PDF in bytes */ size: number; /** If CORS is enabled for all of the images referenced in the sample canvases */ corsSupported: boolean; }; /** Estimate the final size of the PDF for a given manifest. * * This will randomly sample a few representative canvases from the manifest, * check their size in bytes and extrapolate from that to all canvases. * * @throws {Error} if the manifest cannot be loaded */ declare function estimatePdfSize({ manifest: inputManifest, concurrency, scaleFactor, filterCanvases, numSamples, }: EstimationParams): Promise; type ProgressMessageCode = 'generate-cover-page' | 'generate-pages' | 'finishing'; type ProgressNotification = ImageDownloadFailureNotification | OcrDownloadFailureNotification; type ImageDownloadFailureNotification = { code: 'image-download-failure'; canvasIndex: number; numFailed: number; numTotal: number; details: { [imageUrl: string]: string; }; }; type OcrDownloadFailureNotification = { code: 'ocr-download-failure'; canvasIndex: number; ocrUrl: string; }; type ConversionReport = { fileSizeBytes: number; numPages: number; fileName?: string; failedImages?: Array<{ canvasIndex: number; numFailed: number; numTotal: number; details: { [imageUrl: string]: string; }; }>; failedOcr?: Array<{ canvasIndex: number; ocrUrl: string; }>; }; type ConversionReportWithData = ConversionReport & { data: Blob; }; declare function convertManifest(inputManifest: string | Manifest | Presentation2.Manifest, outputStream: Writable | WritableStream, options: ConvertOptions): Promise; declare function convertManifest(inputManifest: string | Manifest | Presentation2.Manifest, outputStream: undefined, options: ConvertOptions): Promise; declare const _default: "0.2.3"; export { ConsoleLogger, ConversionReport, ConversionReportWithData, ConvertOptions, CoverPageParams, Estimation, EstimationParams, ImageDownloadFailureNotification, Logger, OcrDownloadFailureNotification, ProgressMessageCode, ProgressNotification, ProgressStatus, convertManifest, estimatePdfSize, fetchManifestJson, setLogger, _default as version };