PDFium Delphi Component Docs

Object graph inspection and patching

Component: TPdf  ·  Units: PDFium, FPdfCompress
Exports a bounded typed view of active indirect objects and applies constrained dictionary patches transactionally

Syntax

function ExportObjectGraph(Stream: TStream; const Options: TPdfObjectGraphInspectOptions; out Report: TPdfObjectGraphReport): Boolean;

function SaveAsObjectGraphPatched(Stream: TStream; const Operations: TPdfObjectPatchOperations; out Report: TPdfObjectGraphReport; AllowSignedDocument: Boolean = False): Boolean;

function SaveAsObjectGraphPatched(const FileName: string; const Operations: TPdfObjectPatchOperations; out Report: TPdfObjectGraphReport; AllowSignedDocument: Boolean = False): Boolean;

Typed JSON format

ExportObjectGraph stages the active document through a non-incremental native save, writes the typed JSON view to the destination stream, and reports object counts and truncation through Report

The root object, active object count, exported objects, and truncation state are emitted in the versioned pdf-object-graph-v1 envelope

Each value is identified as a dictionary, array, literal or hexadecimal string, name, reference, null, Boolean, integer, real, or keyword

Streams expose their encoded byte count and, when enabled, a SHA-256 digest while their payload remains omitted

Direct objects and members materialized from ObjStm containers use the same representation

Inspection options

MaxObjectsMaximum active objects written before the JSON envelope reports truncated: true
MaxDepthMaximum nested array and dictionary depth from 1 through 32
MaxOutputBytesHard upper bound for the complete UTF-8-compatible JSON byte stream
MaxStringBytesMaximum bytes retained from one PDF string or name
IncludeStreamDigestsCalculates SHA-256 over encoded stream bytes without decoding or exporting the payload

Patch model

SaveAsObjectGraphPatched applies the requested TPdfObjectPatchOperations to the staged object graph and delivers the patched document to a caller stream or a file

Every TPdfObjectPatchOperation selects an exact object number, generation, and top-level dictionary key, then either sets or removes that key

Set operations accept typed null, Boolean, integer, real, name, text string, or indirect reference values and never accept raw PDF syntax

All object identities, generations, references, names, duplicate operations, and target dictionaries are validated before output is delivered

Stream length and filter-chain keys cannot be patched because changing them independently from encoded bytes would corrupt the stream

The writer appends one incremental revision, reconstructs the resulting active graph, strict-loads it through PDFium, and only then writes the caller stream or atomically replaces a file

Policies and limits

Example

Options := TPdfObjectGraphInspectOptions.Default;
Pdf.ExportObjectGraph(JsonStream, Options, Report);
SetLength(Operations, 1);
Operations[0].Kind := popSet;
Operations[0].ObjectNumber := CatalogObjectNumber;
Operations[0].Generation := 0;
Operations[0].Key := 'Lang';
Operations[0].Value.Kind := povTextString;
Operations[0].Value.TextValue := 'en-US';
Pdf.SaveAsObjectGraphPatched('patched.pdf', Operations, Report);

See Also

Incremental save session, SaveAsObjectStream, SaveAs