pdfCreateSetOCGStateAction
Create a /SetOCGState action listing three OCG-handle sets
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);
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.
| Parameter | Description |
|---|---|
IPDF | Document handle. |
On_/OnCount | OCG handles to force visible. |
Off/OffCount | OCG handles to force hidden. |
Toggle/ToggleCount | OCG handles to flip. |
PreserveRB | Accepted 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)
public static extern int pdfCreateSetOCGStateAction(IntPtr IPDF, uint[] On_, uint OnCount, uint[] Off, uint OffCount, uint[] Toggle, uint ToggleCount, [MarshalAs(UnmanagedType.Bool)] bool PreserveRB);
Object Creation
pdfCreateSetOCGStateAction
The …A form takes UTF-8, …W
takes UTF-16; a bare name aliases the ANSI form.
Worked examples — complete programs in ten languages.