BOOL32 __stdcall pdfSetFieldExpValue(PPDF IPDF, uint32_t AField, uint32_t ValIndex, const char* Value, const char* ExpValue, BOOL32 Selected);
BOOL32 __stdcall pdfSetFieldExpValueA(PPDF IPDF, uint32_t AField, uint32_t ValIndex, const char* Value, const char* ExpValue, BOOL32 Selected);
BOOL32 __stdcall pdfSetFieldExpValueW(PPDF IPDF, uint32_t AField, uint32_t ValIndex, const wchar_t* Value, const char* ExpValue, BOOL32 Selected);
BOOL32 __stdcall pdfSetFieldExpValueEx(PPDF IPDF, uint32_t AField, uint32_t ValIndex, BOOL32 Selected, BOOL32 DefSelected);
function pdfSetFieldExpValueA(const IPDF: PPDF; AField: Cardinal; ValIndex: Cardinal; const Value, ExpValue: PAnsiChar; Selected: LongBool): LongBool; stdcall;
function pdfSetFieldExpValueW(const IPDF: PPDF; AField: Cardinal; ValIndex: Cardinal; const Value: PWideChar; const ExpValue: PAnsiChar; Selected: LongBool): LongBool; stdcall;
function pdfSetFieldExpValueEx(const IPDF: PPDF; AField: Cardinal; ValIndex: Cardinal; Selected, DefSelected: LongBool): LongBool; stdcall;
Purpose. Add a Choice-field /Opt entry (export value + display value pair), optionally marking it as the field's current selected value.
Description. **Important: pdfSetFieldExpValue's ValIndex parameter is completely dropped — AddValToChoiceField *always appends* the new pair to the end of the /Opt array unconditionally, regardless of what ValIndex is set to; there is no insert-at-index or replace-at-index behavior despite the parameter's strong naming implication. Repeated calls simply grow the option list by one entry each time, always at the end. pdfSetFieldExpValueEx is a different operation — it does not add a new option; it instead marks an existing** /Opt entry at ValIndex as selected/deselected (SetFieldExpValueSelectedH), a genuinely index-addressed call, in contrast to the plain form's ignored index.
Parameters.
| Parameter | Description |
|---|---|
IPDF | Document handle. |
AField | Target Choice field handle. |
ValIndex | *(plain)* Accepted but silently dropped — the new pair is always appended, never inserted/replaced at this index. *(Ex)* Genuinely used — the existing option to select/deselect. |
Value, ExpValue | *(plain only)* The new option's display/export values. |
Selected | *(plain)* Whether to also set this new option as the field's current value. *(Ex)* Whether to select the existing option at ValIndex. |
DefSelected | *(Ex only)* Whether to also mark it as the field's default. |
Return value. True if AField resolves; False otherwise.
Remarks. To build an ordered option list, call pdfSetFieldExpValue repeatedly in the desired final order — there is no way to insert into the middle of an already-populated list through this call.
C# (P/Invoke)
[return: MarshalAs(UnmanagedType.Bool)]
Forms
pdfSetFieldExpValueEx
The …A form takes UTF-8, …W
takes UTF-16; a bare name aliases the ANSI form.
Worked examples — complete programs in ten languages.