TPDFContentFilterCallback

Data types, content stream editing

Description

TPDFContentFilterCallback is the handler accepted by ApplyContentFilterChain and registered in a TPDFContentFilterChain. It receives the parsed TPDFContentProgram of one content layer and may insert, delete or mutate instructions in place; after the chain accepts the layer, the program is serialised back to the page.

The type is declared as a plain Function, without Of Object, so handlers are ordinary routines and per-call context travels through the FilterData pointer instead of a Self reference. ApplyContentFilterChain forwards a single pointer to its one callback; TPDFContentFilterChain.Add keeps one pointer per registered filter.

Syntax

Delphi

TPDFContentFilterCallback = Function(Program_: TPDFContentProgram;
  Const LayerName: AnsiString; FilterData: Pointer): TPDFContentFilterResult;

Parameters

Program_The parsed instruction list of one content layer; edits are serialised with Emit after the chain accepts the layer
LayerNameLayer identifier in the form L1, L2 and so on, matching the layer ordinal on the page
FilterDataThe caller-defined pointer registered with the filter, passed through unchanged; Nil when none was supplied

Return values

cfrContinueKeep the current edits and let the next filter run; the layer is written back once every filter has accepted it
cfrStopAbandon the remaining filters for this layer; the layer keeps its original bytes and processing continues with the next layer

Remarks

The program and its private object structure are freed after the layer has been emitted, so a callback must not keep operand references past its own call.

Returning cfrStop discards the work of earlier filters for the same layer as well, because the layer is never written back.

A layer that fails to parse is skipped before any callback runs, so a filter only ever sees a well-formed instruction list.

See also

ApplyContentFilterChain, ApplyContentFilterChainExt, TPDFContentFilterChain, TPDFContentProgram, TPDFContentFilterResult, NewContentFilterChain