API referenceForms

pdfSetXFAFormFieldValue

Get/set a datasets leaf's text value, addressed by

C
const char*    __stdcall pdfGetXFAFormFieldValueA(PPDF IPDF, const char* Name);
const wchar_t* __stdcall pdfGetXFAFormFieldValueW(PPDF IPDF, const wchar_t* Name);
int32_t __stdcall pdfSetXFAFormFieldValueA(PPDF IPDF, const char* Name, const char* Value);
int32_t __stdcall pdfSetXFAFormFieldValueW(PPDF IPDF, const wchar_t* Name, const wchar_t* Value);
Delphi
function pdfGetXFAFormFieldValueA(const IPDF: PPDF; Name: PAnsiChar): PAnsiChar; stdcall;
function pdfGetXFAFormFieldValueW(const IPDF: PPDF; Name: PWideChar): PWideChar; stdcall;
function pdfSetXFAFormFieldValueA(const IPDF: PPDF; Name, Value: PAnsiChar): Integer; stdcall;
function pdfSetXFAFormFieldValueW(const IPDF: PPDF; Name, Value: PWideChar): Integer; stdcall;

Purpose. Get/set a datasets leaf's text value, addressed by name (a first-match, depth-first search — see Remarks).

Description. The getter re-parses the datasets packet on every call, finds the first leaf whose local name matches Name (LumasXfaFindLeaf, case-insensitive SameText), and returns its text. The setter does the same lookup, replaces the leaf's text, re-serializes the entire packet back into FXFAData[idx], and — undocumented by the ABI but a real, deliberate cross-write — also mirrors the new value into a same-named AcroForm text field's /V if one resolves via FindFieldByNameH/SetTextFieldValue. This keeps a hybrid XFA form's AcroForm fallback appearance consistent for viewers that only read /V and ignore XFA, per an inline comment ("a hybrid XFA form keeps the value in BOTH the XFA datasets AND the AcroForm /V. Mirror the new value ... so non-XFA viewers ... stay consistent"). This mirroring is one-directional (Set only) — reading via pdfGetXFAFormFieldValue never falls back to the AcroForm /V.

Parameters.

ParameterDescription
IPDFDocument handle.
NameThe datasets leaf's local element name (first depth-first match wins if duplicated).
Value*(Set only)* New text value.

Return value. Getter: the value, empty if Name doesn't resolve or there's no datasets packet. Setter: 1 on success; 0 if Name doesn't resolve.

Remarks. LumasXfaFindLeaf returns the first leaf (depth-first) whose local name matches — if the dataset has two same-named leaves in different branches (a legitimate XFA pattern, e.g. repeated subform instances), only the first is ever reachable through this by-name API; the rest are enumerable via pdfGetXFAFormFieldName/Count but not individually settable by name once a same-named earlier leaf exists.

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
public static extern int pdfSetXFAFormFieldValueW(IntPtr IPDF, IntPtr Name, IntPtr Value);
public static extern int pdfSetXFAFormFieldValue(IntPtr IPDF, IntPtr Name, IntPtr Value);
public static extern int pdfSetXFAFormFieldValueA(IntPtr IPDF, IntPtr Name, IntPtr Value);
Area
Forms
Category

Setters

Exported names

pdfSetXFAFormFieldValueW pdfSetXFAFormFieldValue pdfSetXFAFormFieldValueA

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.