SearchAndReplaceText

Text

Description

Search-and-replace over a page range: every hit of Query is located with the same engine as SearchText, the original text block is covered with an opaque white rectangle, and the replacement text is drawn at the block's top-left origin. This is a layout-level overlay replacement, not a content-stream byte rewrite; the original glyphs stay in the document under the mask

By default the replacement is drawn in the caller's currently selected font, size and text colour, so call SelectFont, SetTextSize and SetTextColor first. With soPreserveStyle the replacement instead inherits each hit block's own font size and colour, read back from the text-extraction model so it matches the covered glyphs

Syntax

Delphi

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

Parameters

QueryThe text to find; an empty Query or empty Replacement returns 0 without changing the document
ReplacementThe text drawn over each masked hit block
OptionsSearch options as in SearchText, for example soCaseSensitive and soWholeWord; soPreserveStyle is specific to this function and makes each replacement inherit the hit block's text size and colour
PageRangePages to search (empty = all)

Return values

>= 0The number of hits that were masked and redrawn
0Nothing was replaced: no document is loaded, Query or Replacement is empty, or no hit was found

Remarks

The page and font selected by the caller are restored before the function returns. A single call processes at most 4096 hits. When the original text must be gone from the content stream rather than covered, use SearchAndReplaceTextInContent, which rewrites the show-text operators in place

See also

SearchText, SearchAndReplaceTextInContent, TPDFlibSearchOption, SelectFont, SetTextSize