SearchAndReplaceTextInContent

Extraction

Description

Performs TRUE content-stream text replacement: rewrites the Tj/TJ/'/" show-text operators in place so the original text is gone from the stream and cannot be recovered. This is fundamentally different from SearchAndReplaceText, which only overlays a white rectangle plus new text on top of the original glyphs (the original bytes remain).

Locates hits via SearchText, maps each hit rectangle to its covering show-text instruction via the content-stream analyser (FindInstructionsInRect), rewrites the operand string via ReplaceTextRun, and writes the layer back.

Caveats: TJ array kerning is collapsed to an unkerned string; the replacement text must be encodable in the existing font's encoding or glyphs render as .notdef. The method does not embed new fonts.

Syntax

Delphi

Function TPDFlib.SearchAndReplaceTextInContent(Const Query, Replacement: WideString; Options: TPDFlibSearchOptions; Const PageRange: WideString): Integer;

Parameters

QueryThe text to find
ReplacementThe replacement text (must be encodable in the existing font)
OptionssoCaseSensitive / soWholeWord, same as SearchText
PageRangePages to search (empty = all)

Return values

>= 0Number of hits whose underlying show-text instruction was rewritten