API referenceText

psrReplaceSelText

Replace the text of a selection (from

CategoryInteractive text editing
Notefails 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

C
BOOL32 __stdcall psrReplaceSelText(PPDF IPDF, IPSR Ctx, TReplaceTextFlags Flags, TTextSelection* SelText, const wchar_t* Text, uint32_t TextLen);
Delphi
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):

Delphi
TReplaceTextFlags = (rtfDefault = 0);

Parameters

ParameterTypeDescription
IPDFPPDFInstance handle.
CtxIPSRParsed context.
FlagsTReplaceTextFlagsOnly rtfDefault exists.
SelTextTTextSelection*The selection to replace; if TextOP=NULL, falls back to the context's last psrFindText selection.
TextPWideCharReplacement text.
TextLenCardinalLength of Text.

Return valueTRUE 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 alsopsrFindText, psrWriteToPage

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
[return: MarshalAs(UnmanagedType.Bool)]
Area
Text
Category

Misc

Exported names

psrReplaceSelText

String variants

The …A form takes UTF-8, …W takes UTF-16; a bare name aliases the ANSI form.

See working code

Worked examples — complete programs in ten languages.