import { PdfObject } from '../core/objects/pdf-object.js'; import { PdfIndirectObject } from '../core/objects/pdf-indirect-object.js'; import { PdfXRefTable } from '../core/objects/pdf-xref-table.js'; import { PdfTrailer, PdfTrailerEntries } from '../core/objects/pdf-trailer.js'; import { PdfStream, PdfXRefStream, PdfXRefStreamEntry } from '../core/objects/pdf-stream.js'; import { PdfDictionary } from '../core/objects/pdf-dictionary.js'; import { Ref } from '../core/ref.js'; /** * Manages cross-reference (xref) lookup for PDF objects. * Handles both traditional xref tables and xref streams, including hybrid documents. * Supports linking multiple revisions through the Prev chain. */ export declare class PdfXrefLookup { /** The underlying xref object (either a table or stream) */ object: PdfIndirectObject | PdfXRefTable; /** Map of object numbers to their xref entries */ entries: Map; /** Trailer dictionary containing document metadata references */ trailerDict: PdfDictionary; /** Reference to the previous xref lookup in the revision chain */ prev?: PdfXrefLookup; private type?; private hybridXRefStream?; /** * Creates a new xref lookup instance. * * @param options - Configuration options * @param options.type - Type of xref ('table' or 'stream') * @param options.object - Pre-existing xref table or stream object * @param options.trailerDict - Pre-existing trailer dictionary * @param options.prev - Previous xref lookup to link to */ constructor(options?: { type?: 'table' | 'stream'; object?: PdfIndirectObject | PdfXRefTable; trailerDict?: PdfDictionary; prev?: PdfXrefLookup; }); /** * Links this xref to a previous xref lookup. * Copies missing trailer entries from the previous xref. * * @param xref - The previous xref lookup to link to * @throws Error if trying to set self as previous (would create circular reference) or if offsets match (would create ambiguous or invalid xref chain) */ setPrev(xref: PdfXrefLookup): void; /** * Sets the byte offset of the xref object. */ set offset(value: Ref); /** * Gets the byte offset of the xref object. */ get offset(): Ref; /** * Creates xref lookups from an array of PDF objects. * Parses both xref tables and xref streams, linking them via the Prev chain. * * @param objects - Array of PDF objects to parse * @returns The most recent xref lookup with linked previous lookups */ static fromObjects(objects: PdfObject[]): PdfXrefLookup; /** * Creates an xref lookup from a traditional xref table and trailer. * Handles hybrid xref documents with both table and stream entries. * * @param xrefTable - The xref table object * @param trailer - The trailer object * @param objects - Optional array of objects for resolving hybrid xref streams * @returns A new PdfXrefLookup instance */ static fromXrefTable(xrefTable: PdfXRefTable, trailer: PdfTrailer, objects?: PdfObject[]): PdfXrefLookup; /** * Creates an xref lookup from an xref stream object. * * @param streamObject - The indirect object containing the xref stream * @returns A new PdfXrefLookup instance */ static fromXrefStream(streamObject: PdfIndirectObject): PdfXrefLookup; /** * Gets the size of the xref table (highest object number + 1). * Ensures size is at least as large as the previous revision. */ get size(): number; /** * Sets the size of the xref table. */ set size(value: number); /** * Gets all xref entries as an array. */ get entriesValues(): PdfXRefStreamEntry[]; /** * Links xref entries to their corresponding indirect objects. * Updates byte offset references to point to actual object offsets. * * @param objects - Array of indirect objects to link */ linkIndirectObjects(objects: PdfIndirectObject[]): void; /** * Links this xref to a previous xref lookup based on the Prev trailer entry. * * @param objects - Array of xref lookups to search for the previous one */ linkPrev(objects: PdfXrefLookup[]): void; /** * Updates the xref object with current entries. * Handles both table and stream formats, including hybrid documents. * * @returns The updated xref object */ update(): PdfIndirectObject | PdfXRefTable; /** * Reserves a contiguous block of object numbers without registering objects. * Use this to pre-assign numbers to objects that will live inside an ObjStm. * * @param count - Number of object numbers to reserve * @returns The first reserved object number */ reserveObjectNumbers(count: number): number; /** * Adds an indirect object to the xref lookup. * Assigns an object number if not already set. * * @param newObject - The indirect object to add * @param options - Options for compressed objects * @param options.parentObjectNumber - Object number of the containing object stream * @param options.indexInStream - Index within the object stream * @throws Error if trying to add compressed object with non-zero generation number */ addObject(newObject: PdfIndirectObject, options?: { parentObjectNumber?: number; indexInStream?: number; }): void; /** * Removes an indirect object from the xref lookup. * Also removes any trailer references to the object. * * @param object - The indirect object to remove */ removeObject(object: PdfIndirectObject): void; /** * Gets an xref entry by object number. * Falls back to the previous xref if not found in current entries. * * @param objectNumber - The object number to look up * @returns The xref entry or undefined if not found */ getObject(objectNumber: number): PdfXRefStreamEntry | undefined; /** * Generates the trailer section objects for this xref. * Includes xref table/stream, trailer (if using table), startxref, and EOF. * * @returns Array of objects forming the trailer section */ toTrailerSection(): PdfObject[]; }