/** * PDF file writer. * * Assembles a complete PDF 2.0 document from indirect objects. * Handles the four sections of a PDF file: * 1. Header (%PDF-2.0) * 2. Body (indirect objects) * 3. Cross-reference table * 4. Trailer (with document catalog reference) * * Also provides {@link buildIncremental} for appending incremental updates * to an existing PDF without rewriting the original bytes. * * Encryption uses AES-256 (V=5, R=5) per ISO 32000-2:2020. * * @see ISO 32000-2:2020, Chapter 7.5 โ€” File Structure */ import type { EncryptionState } from "./encryption.js"; import { PdfDict } from "./pdf-object.js"; import type { PdfContentStream } from "./pdf-stream.js"; /** * Constructs a valid PDF 2.0 file from a set of indirect objects. * * Usage: * 1. Allocate object numbers with allocObject() * 2. Add objects with addObject() or addStreamObject() * 3. Call build() to produce the final Uint8Array */ export declare class PdfWriter { private nextObjectNumber; private objects; private catalogRef; private infoRef; private encryption; private pdfVersion; /** * Set the PDF version string (e.g. "1.4", "1.7", "2.0"). * Default is "2.0". */ setVersion(version: string): void; /** * Enable encryption for this document. */ setEncryption(state: EncryptionState): void; /** * Allocate the next object number without adding content yet. * Use this for forward references (e.g., page references in the page tree). */ allocObject(): number; /** * Add a dictionary object to the PDF. * @param objectNumber - Previously allocated object number * @param dict - The dictionary content */ addObject(objectNumber: number, dict: PdfDict | string): void; /** * Add a stream object (dictionary + binary stream data) to the PDF. * The /Length key is automatically added to the dictionary. * * @param objectNumber - Previously allocated object number * @param dict - The stream dictionary * @param data - Stream content (PdfContentStream or raw Uint8Array) * @param options - Optional settings (e.g. `{ compress: false }` to skip zlib) */ addStreamObject(objectNumber: number, dict: PdfDict, stream: PdfContentStream): void; addStreamObject(objectNumber: number, dict: PdfDict, data: Uint8Array): void; addStreamObject(objectNumber: number, dict: PdfDict, data: Uint8Array, options: { compress?: boolean; }): void; /** * Return all stored objects for inspection (e.g., incremental update remapping). * Stream objects include their binary data. */ getObjects(): Array<{ objectNumber: number; content: string; streamData?: Uint8Array; }>; /** * Set the document catalog object number. * This is required and references the root of the document structure. */ setCatalog(objectNumber: number): void; /** * Create and add the document information dictionary. */ addInfoDict(options: { title?: string; author?: string; subject?: string; creator?: string; }): number; /** * Create and add a Page dictionary. */ addPage(options: { parentRef: number; width: number; height: number; contentsRef: number | string; resourcesRef: number; annotRefs?: number[]; }): number; /** * Create and add the Catalog dictionary. * * @param pagesRef - Object number of the Pages tree root * @param optionsOrOutlinesRef - Either an outlinesRef number (legacy) or an options object */ addCatalog(pagesRef: number, optionsOrOutlinesRef?: number | { outlinesRef?: number; extraEntries?: Array<[key: string, value: string]>; }): number; /** * Build the complete PDF file as a Uint8Array. */ build(): Uint8Array; } /** * Build an incremental update that appends new/modified objects to an * existing PDF without rewriting the original bytes. * * The result is `originalData + "\n" + new objects + xref + trailer + %%EOF`. * The new trailer's `/Prev` points to the original xref offset so that PDF * readers can follow the chain of incremental updates. * * @param originalData - The original, unmodified PDF bytes (preserved byte-for-byte) * @param modifiedObjects - Map of object number โ†’ serialized content. * Values are either a plain string (for non-stream objects) or * `{ dict, data }` for stream objects. * @param newTrailerEntries - Additional/override entries for the new trailer. * Keys like `/Root`, `/Info`, `/Encrypt`, `/ID` are preserved from the * original trailer by default but can be overridden here. * * @see ISO 32000-2:2020, ยง7.5.6 โ€” Incremental Updates */ export declare function buildIncremental(originalData: Uint8Array, modifiedObjects: Map, newTrailerEntries: Map): Uint8Array;