API referenceForms

pdfGetFieldCalcOrder

Read/reorder the AcroForm /CO calculation-order array —

C
int32_t __stdcall pdfGetFieldCalcOrder(PPDF IPDF, uint32_t* Out);
BOOL32 __stdcall pdfSetFieldCalcOrder(PPDF IPDF, int32_t CurrIndex, uint32_t NewIndex);
Delphi
function pdfGetFieldCalcOrder(const IPDF: PPDF; var Out: PCardinal): Integer; stdcall;
function pdfSetFieldCalcOrder(const IPDF: PPDF; CurrIndex: Integer; NewIndex: Cardinal): LongBool; stdcall;

Purpose. Read/reorder the AcroForm /CO calculation-order array — the field evaluation sequence used when JavaScript calculation scripts depend on other fields' values.

Description. Verified major bug: the getter and setter operate on two entirely separate, disconnected backing arrays. pdfSetFieldCalcOrder genuinely reorders FCalcOrder — a real array populated incrementally as calculation-capable fields register and consulted at serialization time to emit the document's actual /CO array (per an inline comment: "Real reorder — the emitted AcroForm /CO array reflects it"). But pdfGetFieldCalcOrder never reads FCalcOrder at all — it instead builds a completely fresh array (FCalcOrderBuf) on every call by sorting FFieldByHandle's keys in ascending handle-number order (which, since handles are assigned incrementally at creation, is simply creation order). **The practical consequence: calling pdfSetFieldCalcOrder to genuinely reorder calculation — and having that reordering correctly reflected in the final output PDF's /CO array — produces *no visible change* when read back via pdfGetFieldCalcOrder**, which always reports fields in creation order regardless of any prior pdfSetFieldCalcOrder calls. A caller using this getter to verify or display the current calculation order will see stale, incorrect information even though the underlying document state (and eventual output) is correct.

Parameters.

ParameterDescription
IPDFDocument handle.
OutOutput: field handles — always in creation order, never reflecting pdfSetFieldCalcOrder changes.
CurrIndex, NewIndex0-based positions within the real /CO order (FCalcOrder) to move a field between — genuinely effective, just not observable via the getter.

Return value. pdfGetFieldCalcOrder: the field count; 0 if IPDF invalid or Out is a null pointer. pdfSetFieldCalcOrder: True if CurrIndex is in range for the real /CO array.

Remarks. Trust pdfSetFieldCalcOrder's effect on the actual output document; do not use pdfGetFieldCalcOrder to verify it took effect — that getter is disconnected from the real state.

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
public static extern int pdfGetFieldCalcOrder(IntPtr IPDF, ref IntPtr @Out);
Area
Forms
Category

Forms

Exported names

pdfGetFieldCalcOrder

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.