API referenceGraphics

pdfCreateSetOCGStateAction

Create a /SetOCGState action listing three OCG-handle sets

C
int32_t __stdcall pdfCreateSetOCGStateAction(PPDF IPDF, uint32_t* On_, uint32_t OnCount, uint32_t* Off, uint32_t OffCount, uint32_t* Toggle, uint32_t ToggleCount, BOOL32 PreserveRB);
Delphi
function pdfCreateSetOCGStateAction(const IPDF: PPDF; On_: PCardinal; OnCount: Cardinal; Off: PCardinal; OffCount: Cardinal; Toggle: PCardinal; ToggleCount: Cardinal; PreserveRB: LongBool): Integer; stdcall;

Purpose. Create a /SetOCGState action listing three OCG-handle sets to turn ON, OFF, or toggle when the action fires.

Description. Reads all three handle arrays (On_/Off/Toggle, each with its own count — a null array pointer with a matching zero count is fine, but a null pointer paired with a non-zero count produces an array of zero-value entries rather than failing) and registers a new document action (kind 12) carrying the three lists verbatim, to be serialized later as the action's /ON//OFF//Toggle OCG-reference arrays. The PreserveRB parameter is accepted by the ABI but never passed through to the underlying action-registration call — it is silently dropped. Its name implies it should control the PDF /SetOCGState action's own /PreserveRB flag (whether the action preserves each targeted OCG's current radio-button-group exclusivity when applying the toggle), but no such flag is ever recorded or serialized regardless of the value passed.

Parameters.

ParameterDescription
IPDFDocument handle.
On_/OnCountOCG handles to force visible.
Off/OffCountOCG handles to force hidden.
Toggle/ToggleCountOCG handles to flip.
PreserveRBAccepted but silently dropped — has no effect on the serialized action regardless of value.

Return value. The new action handle on success; 0 if IPDF is invalid.

See also. pdfSetOCGState (the immediate, non-action-based sibling — sets visibility right now rather than deferring to an action trigger).

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
public static extern int pdfCreateSetOCGStateAction(IntPtr IPDF, uint[] On_, uint OnCount, uint[] Off, uint OffCount, uint[] Toggle, uint ToggleCount, [MarshalAs(UnmanagedType.Bool)] bool PreserveRB);
Area
Graphics
Category

Object Creation

Exported names

pdfCreateSetOCGStateAction

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.