import { n as PdfDocument } from "./pdfDocument-Bi-NoyXv.mjs"; import { C as PdfRef, _ as PdfDict, v as PdfName, w as PdfStream } from "./pdfForm-BiyNtYem.mjs"; //#region src/parser/contentStreamParser.d.ts /** * A single operand value in a content stream. * * - `number` — integer or real * - `string` — literal `(…)` or hex `<…>` string (decoded to a JS string) * - `boolean` — `true` / `false` * - `null` — the PDF `null` keyword * - `PdfName` — a `/Name` * - `Operand[]` — a PDF array `[…]` */ type Operand = number | string | boolean | null | PdfName | Operand[]; /** * A parsed content-stream operator with its preceding operands. */ interface ContentStreamOperator { /** The operator keyword, e.g. `"BT"`, `"Tf"`, `"Tj"`, `"re"`, `"cm"`. */ operator: string; /** The operand values that preceded this operator. */ operands: Operand[]; } /** * Parse a PDF content stream into an ordered list of operators. * * @param data - The raw content-stream bytes (already decompressed). * @returns An array of operators in document order. */ declare function parseContentStream(data: Uint8Array): ContentStreamOperator[]; //#endregion //#region src/parser/textExtractor.d.ts /** * A single extracted text item with position and font information. */ interface TextItem { /** The extracted text string. */ text: string; /** Horizontal position in user-space units. */ x: number; /** Vertical position in user-space units. */ y: number; /** Approximate width of the text in user-space units. */ width: number; /** Approximate height of the text in user-space units (based on font size). */ height: number; /** Font size in user-space units. */ fontSize: number; /** Font resource name (e.g. `"/F1"`). */ fontName: string; } /** * Options for text extraction. */ interface TextExtractionOptions { /** * Include position information. * Default: `false` for performance. */ withPositions?: boolean | undefined; } /** * Extract plain text from a sequence of parsed content-stream operators. * * This function concatenates all text-showing operator strings, inserting * spaces between text objects (BT/ET blocks) and newlines at line breaks * (`T*`, `Td`, `TD`). * * @param operators - Parsed content-stream operators. * @param resources - Optional page `/Resources` dictionary (used to look * up font encodings and ToUnicode CMaps). * @param options - Extraction options. * @returns The extracted text as a single string. */ declare function extractText(operators: ContentStreamOperator[], resources?: PdfDict, options?: TextExtractionOptions): string; /** * Extract text with position information from a parsed content stream. * * Each returned {@link TextItem} includes the text string, its position * (x, y), dimensions (width, height), font size, and font name. * * @param operators - Parsed content-stream operators. * @param resources - Optional page `/Resources` dictionary. * @returns An array of positioned text items. */ declare function extractTextWithPositions(operators: ContentStreamOperator[], resources?: PdfDict): TextItem[]; //#endregion //#region src/parser/streamDecode.d.ts /** * Decode (decompress) PDF stream data that may have one or more filters * applied. Filters are applied in the order they appear in the array * (first entry is the outermost encoding, decoded first). * * @param data - The raw (encoded) stream bytes. * @param filters - A single filter name or an ordered array of filter * names (e.g. `"FlateDecode"` or * `["ASCIIHexDecode", "FlateDecode"]`). * @param decodeParms - Optional decode parameters — a single `PdfDict` or * an array of `PdfDict | null` parallel to `filters`. * @returns The fully decoded bytes. */ declare function decodeStream(data: Uint8Array, filters: string | string[], decodeParms?: PdfDict | PdfDict[] | null): Uint8Array; //#endregion //#region src/parser/parseError.d.ts /** * @module parser/parseError * Structured error class for PDF parsing failures. * @packageDocumentation */ declare class PdfParseError extends Error { readonly name = "PdfParseError"; readonly offset: number; readonly expected: string; readonly actual: string; readonly hexContext: string; constructor(options: { message: string; offset: number; expected?: string | undefined; actual?: string | undefined; data?: Uint8Array | undefined; cause?: Error | undefined; }); } declare function formatHexContext(data: Uint8Array, offset: number, windowSize?: number): string; //#endregion //#region src/assets/image/imageExtract.d.ts /** * Information about a single image XObject in a PDF document. */ interface ImageInfo { /** The PdfStream object for this image (can be mutated for in-place optimization). */ readonly stream: PdfStream; /** The indirect reference to this stream in the registry. */ readonly ref: PdfRef; /** Resource name on the page (e.g. '/Im1'). */ readonly name: string; /** Zero-based page index where this image appears. */ readonly pageIndex: number; /** Image width in pixels. */ readonly width: number; /** Image height in pixels. */ readonly height: number; /** Bits per component (typically 8). */ readonly bitsPerComponent: number; /** PDF color space name (e.g. 'DeviceRGB', 'DeviceGray', 'DeviceCMYK'). */ readonly colorSpace: string; /** Number of color channels (1, 3, or 4). */ readonly channels: number; /** PDF filter name(s) applied to this stream. */ readonly filters: readonly string[]; /** Size of the compressed stream data in bytes. */ readonly compressedSize: number; } /** * Extract all image XObjects from a PDF document. * * Walks every page's `/Resources /XObject` dictionary and collects * metadata for each image XObject found. * * @param doc - A parsed `PdfDocument`. * @returns An array of `ImageInfo` objects, one per image XObject. * * @example * ```ts * import { loadPdf, extractImages } from 'modern-pdf-lib'; * * const doc = await loadPdf(pdfBytes); * const images = extractImages(doc); * * for (const img of images) { * console.log(`${img.name}: ${img.width}x${img.height} ${img.colorSpace} (${img.compressedSize} bytes)`); * } * ``` */ declare function extractImages(doc: PdfDocument): ImageInfo[]; /** * Decode image stream data into raw pixels. * * For DCTDecode (JPEG) streams, returns the raw JPEG bytes (not decoded * to pixels) since JPEG decoding requires the WASM module. * * For FlateDecode and other filters, fully decodes the stream. * * @param imageInfo - An `ImageInfo` from `extractImages()`. * @returns The decoded stream data. */ declare function decodeImageStream(imageInfo: ImageInfo): Uint8Array; //#endregion //#region src/assets/image/compressionAnalysis.d.ts /** * Per-image analysis result. */ interface ImageAnalysis { /** Resource name on the page (e.g. '/Im1'). */ readonly name: string; /** Zero-based page index where this image appears. */ readonly pageIndex: number; /** Image width in pixels. */ readonly width: number; /** Image height in pixels. */ readonly height: number; /** Size of the current (compressed) stream data in bytes. */ readonly currentSize: number; /** Description of the current encoding (e.g. 'FlateDecode', 'DCTDecode'). */ readonly currentFormat: string; /** PDF color space name (e.g. 'DeviceRGB', 'DeviceGray'). */ readonly colorSpace: string; /** Estimated JPEG-encoded size in bytes. */ readonly estimatedJpegSize: number; /** Estimated savings in bytes (`currentSize - estimatedJpegSize`). */ readonly estimatedSavings: number; /** Savings as a percentage of the current size. */ readonly savingsPercent: number; /** Whether the image is effectively grayscale (even if stored as RGB). */ readonly isGrayscale: boolean; /** Effective DPI of the image at its display size, or `undefined` if unknown. */ readonly effectiveDpi: number | undefined; /** Recommended action for this image. */ readonly recommendation: 'recompress' | 'keep' | 'downscale' | 'grayscale'; } /** * Full document analysis report. */ interface AnalysisReport { /** Per-image analysis results. */ readonly images: readonly ImageAnalysis[]; /** Total size of all image streams in bytes. */ readonly totalCurrentSize: number; /** Total estimated size after optimization. */ readonly totalEstimatedSize: number; /** Total estimated savings in bytes. */ readonly totalSavings: number; /** Total savings as a percentage of total current size. */ readonly totalSavingsPercent: number; } /** * Options for `analyzeImages()`. */ interface AnalyzeImagesOptions { /** * JPEG quality used for size estimation (1–100). * * Default: `80`. */ readonly quality?: number; /** * Maximum allowed DPI. Images exceeding this at their display size * receive a `'downscale'` recommendation. * * Default: `150`. */ readonly maxDpi?: number; } /** * Analyze all images in a PDF and report potential savings without * modifying the document. * * For each image XObject with `bitsPerComponent === 8` and 1–4 channels, * the function estimates the JPEG-encoded size — using the WASM encoder * when available, or a heuristic fallback otherwise. * * @param doc - A parsed `PdfDocument`. * @param options - Optional quality and maxDpi settings. * @returns An `AnalysisReport` with per-image and aggregate statistics. * * @example * ```ts * import { loadPdf, analyzeImages } from 'modern-pdf-lib'; * * const doc = await loadPdf(pdfBytes); * const report = analyzeImages(doc, { quality: 75, maxDpi: 150 }); * * console.log(`Total savings: ${report.totalSavingsPercent.toFixed(1)}%`); * for (const img of report.images) { * console.log(` ${img.name}: ${img.recommendation} (${img.savingsPercent.toFixed(1)}%)`); * } * ``` */ declare function analyzeImages(doc: PdfDocument, options?: AnalyzeImagesOptions): AnalysisReport; //#endregion export { parseContentStream as _, ImageInfo as a, PdfParseError as c, TextExtractionOptions as d, TextItem as f, Operand as g, ContentStreamOperator as h, analyzeImages as i, formatHexContext as l, extractTextWithPositions as m, AnalyzeImagesOptions as n, decodeImageStream as o, extractText as p, ImageAnalysis as r, extractImages as s, AnalysisReport as t, decodeStream as u }; //# sourceMappingURL=compressionAnalysis-Ch7t-HXn.d.mts.map