API referenceText

pdfReplacePageText

Nominally "replace page text"; actually replaces the first

CategoryPositional page-text replacement
Exported namespdfReplacePageTextA
Notenot a find/replace by content, and every occurrence of the matched bytes is replaced (see Remarks)

Purpose — Nominally "replace page text"; actually replaces the first show-text operator's literal string content on the active page, and every other occurrence of those exact bytes elsewhere on the same page.

Description — the name is misleading; read this before using it.

  1. Locates the first Tj (or first string inside a TJ array) operator on D.ActivePageIndex and captures its raw bytes (oldS) — you do not supply the text to search for; it is always whatever the first show-string on the page happens to contain.
  2. Rewrites the entire page content stream, replacing every occurrence of oldS as a byte substring inside any literal (...) or hex <...> show-string on the page with NewText — not just the one operator it was found in. If that exact string appears in multiple show-text operators (e.g. a repeated header/footer fragment), all of them change.
  3. Stack is accepted in the exported signature but never read by this implementation.

Declarations

C
BOOL32 __stdcall pdfReplacePageTextA(PPDF IPDF, const char* NewText, TPDFStack* Stack);
Delphi
function pdfReplacePageTextA(const IPDF: PPDF; const NewText: PAnsiChar; var Stack: TPDFStack): LongBool; stdcall; external 'LumasPdf.dll';

Parameters

ParameterTypeDescription
IPDFPPDFInstance handle with an active page.
NewTextPAnsiCharReplacement bytes (ANSI only — this entry point has no W variant; use pdfReplacePageTextEx for Unicode).
StackTPDFStack*Accepted for ABI compatibility; not read.

Return valueTRUE if a first show-string was found and at least one substitution occurred; FALSE if the page has no show-text operators or the active page can't be read.

See alsopdfReplacePageTextEx, pdfReplacePageTextNth

C# (P/Invoke)

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

Core

Exported names

pdfReplacePageTextA

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.