Content Operator Visitors

HotPDF exposes every operation in a decoded content stream through a reference-counted visitor interface and a Delphi event callback without requiring callers to write a PDF tokenizer

Inspect and measure

THPDFContentOperatorEventData identifies the begin-stream, operator, and end-stream phases and reports the operation index, operator name, operand count, byte range, and deterministic state before the current source operator executes

The state contains graphics-state, text-object, marked-content, and compatibility-section depths, while THPDFContentOperatorView provides on-demand read-only operation or operand bytes without copying the complete source stream

Transform or reject

Callbacks select coaKeep, coaDelete, coaReplace, coaStop, or coaReject

Delete and replace actions become sorted non-overlapping AST edits; a rejection publishes no output and coaStop completes successfully after the current operator

State snapshots follow the original source traversal even when an operation is replaced, making repeated inspection deterministic

Budgets and validation

THPDFContentOperatorVisitOptions.Default configures MaxSourceBytes, MaxOperators, MaxLexemes, MaxDepth, MaxReplacementBytes, and ValidateOutput

Cancellation is checked during traversal, and transformed output is parsed again under the same lexeme, depth, and operator limits before it can be returned or written to a loaded page

Malformed input, invalid replacement output, callback exceptions, limit failures, and explicit rejection are distinguished by THPDFContentOperatorVisitStatus and a diagnostic

Loaded-page registration

PDF.ContentOperatorVisitor := Visitor;
PDF.OnContentOperator := HandleContentOperator;
Options := THPDFContentOperatorVisitOptions.Default;
if PDF.VisitLoadedPageContentOperators(0, True, Options,
  CancellationToken, Statistics) then
  UseStatistics(Statistics);

The interface visitor runs before the event callback when both are assigned, and both execute synchronously on the calling thread

With ApplyChanges=True, HotPDF validates the complete transformed stream first, then replaces the page content in one graph mutation and invalidates compiled display-list, raster, disk, font-decoder, and thumbnail caches

Related APIs