| Category | Interactive text editing |
|---|---|
| Note | fails cleanly for alt-font Unicode (see Remarks) |
Purpose — Replace the text of a selection (from psrFindText, or the context's current selection if SelText.TextOP is NULL) with Text.
Description — font-aware re-encoding. Determines the selected run's font: for an embedded-TrueType Type0 or UCS2 CID font, the old and new text are re-encoded into that font's own multi-byte show-string codes (FontCodeBytesForAlias), marking new glyphs into the subset as needed; for a simple font, both old and new text go through a Latin-1 byte conversion. The actual substitution reuses the same whole-content-stream substring replace as pdfReplacePageText (see that entry's Remarks for the "replaces everywhere, not just the matched occurrence" behavior — it applies here too, since both routes call the same PsrReplaceShowText).
Declarations
BOOL32 __stdcall psrReplaceSelText(PPDF IPDF, IPSR Ctx, TReplaceTextFlags Flags, TTextSelection* SelText, const wchar_t* Text, uint32_t TextLen);
function psrReplaceSelText(const IPDF: PPDF; const Ctx: IPSR; Flags: TReplaceTextFlags; var SelText: TTextSelection; const Text: PWideChar; TextLen: Cardinal): LongBool; stdcall; external 'LumasPdf.dll';
TReplaceTextFlags (only one value defined):
TReplaceTextFlags = (rtfDefault = 0);
Parameters
| Parameter | Type | Description |
|---|---|---|
IPDF | PPDF | Instance handle. |
Ctx | IPSR | Parsed context. |
Flags | TReplaceTextFlags | Only rtfDefault exists. |
SelText | TTextSelection* | The selection to replace; if TextOP=NULL, falls back to the context's last psrFindText selection. |
Text | PWideChar | Replacement text. |
TextLen | Cardinal | Length of Text. |
Return value — TRUE on success; FALSE if there's no selection, the underlying substring replace matched zero occurrences, or — a deliberate, documented failure, not a bug — an alternate font is registered on this context (via psrSetAltFont) and the replacement text contains any character outside Latin-1 (code point > 255). Stages the edit on Ctx; does not write to the page until psrWriteToPage.
Remarks — known limitation (fails cleanly). Full alt-font re-encoding for non-Latin-1 replacement text is not yet implemented; rather than emitting corrupted glyphs (silently mapping unrepresentable characters to '?'), this build fails the call outright in that specific combination. Latin-1-only replacement text with an alt font selected, or any replacement text with no alt font selected, both proceed normally.
See also — psrFindText, psrWriteToPage
C# (P/Invoke)
[return: MarshalAs(UnmanagedType.Bool)]
Misc
psrReplaceSelText
The …A form takes UTF-8, …W
takes UTF-16; a bare name aliases the ANSI form.
Worked examples — complete programs in ten languages.