SearchAndReplaceTextInContentEx

Extraction, Unicode, content editing

Description

Replaces every non-overlapping query occurrence in supported page text, using exact source byte ranges and a verified font mapping

The method preserves surrounding text, existing TJ numeric adjustments and the original following text anchor; an empty replacement deletes only the matched characters

All selected hits are planned and rewritten before page content is committed; unrepresentable text, incomplete font mappings or an unsupported source location reject the request without replacing any selected page text

Syntax

Delphi

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

DLL

Function DLSearchAndReplaceTextInContentEx(InstanceID: Integer; Query: PWideChar; Replacement: PWideChar; Options: Integer; PageRange: PWideChar; ReplacementFontID: Integer): Integer; Stdcall;
Function DLSearchAndReplaceTextInContentExA(InstanceID: Integer; Query: PAnsiChar; Replacement: PAnsiChar; Options: Integer; PageRange: PAnsiChar; ReplacementFontID: Integer): Integer; Stdcall;

ActiveX

Function PDFlib::SearchAndReplaceTextInContentEx(Query: WideString; Replacement: WideString; Options: Integer; PageRange: WideString; ReplacementFontID: Integer): Integer;

Parameters

ReplacementFontID 0 uses the original font; a positive value must identify a font in the selected document with a complete verified encoding

A replacement font is selected only for replacement runs and the original font is restored before untouched suffixes; this method does not automatically choose or install a font

DLL and ActiveX Options use the search flags as bits 1, 2, 4, 8, 16, 32, 64 and 128 in enum order; soAcrossLines is bit 16 and is unsupported here; unknown bits are rejected by these facades

DLL A input strings use the instance ANSI-to-wide conversion configuration; use the wide entry point to pass Unicode independently of that configuration

Return values

Returns the number of replaced matches, or 0 for no matches or a rejected request; inspect GetLastUnicodeReplacementDiagnostics to distinguish those outcomes

LastErrorCode 535 reports invalid input or capture limits; 537 reports unsupported editing or encoding; a valid search with no matches reports completed with replacedHits 0

Remarks

Mappings come from a fully supported ToUnicode CMap or a verified simple-font encoding, including supported Differences glyph names; no system-code-page conversion or guessed glyph encoding is used

Simple fonts must supply valid PDF Widths, FirstChar and LastChar, or use an exact standard fourteen Type1 font name without Widths; system font fallback and loose name matching do not authorize exact advance

Named UseCMap inheritance, unresolved mappings, Type3 font advances, vertical writing, nested Form text, synthetic characters, ActualText replacements, transcoded strings, cross-layer matches and partial ligature clusters are reported as unsupported

A complete ligature cluster can be replaced when its original bytes and Unicode mapping are verified; prefixes and suffixes remain in their original font

Search options retain their existing meaning, including case, whole-word, wildcard, diacritic, canonical-equivalence and grapheme constraints; soAcrossLines and calls during an open API scope are rejected

Planning supports up to 4096 matches; captured source snapshots are limited to 64 MiB per stream and 512 MiB in total, with 64 MiB of captured source-location records; the font mapping parser also applies bounded token and code-space limits, with transaction totals of 262144 mappings and 8 Mi UTF-16 target units

These limits constrain retained capture and planning data; existing page loading and rendering have their own allocations, so they are not a guarantee of absolute peak memory usage

Shared content streams and resource dictionaries are copied for selected pages; document selection is restored and stale text-block lists must be extracted again after a successful edit

This operation changes active page content and is not a secure-erasure API: detached objects or earlier incremental revisions can retain original bytes

See also

SearchAndReplaceTextInContent, SearchAndReplaceTextInContentEx, GetLastUnicodeReplacementDiagnostics, SearchText