API referenceCore SDK

pdfCreateOCG

Create a new optional-content group (a "layer").

CategoryOptional content
Exported namespdfCreateOCGA, pdfCreateOCGW
AvailabilityPartial — DisplayInUI/Intent accepted, not applied — see Remarks

Purpose — Create a new optional-content group (a "layer").

Description — Registers a new OCG with Name and its initial Visible state, which becomes both the current display state and the default state restored by pdfLoadLayerConfig(0). The engine assigns an internal PDF-name alias (OC1, OC2, …) used to reference the layer from content streams via /OC /OCn BDC — this alias, not Name, is what pdfBeginLayer writes into the page content.

Declarations

C
int32_t __stdcall pdfCreateOCGA(PPDF IPDF, const char* Name, BOOL32 DisplayInUI, BOOL32 Visible, TOCGIntent Intent);
int32_t __stdcall pdfCreateOCGW(PPDF IPDF, const wchar_t* Name, BOOL32 DisplayInUI, BOOL32 Visible, TOCGIntent Intent);
Delphi
function pdfCreateOCGA(const IPDF: PPDF; const Name: PAnsiChar; DisplayInUI, Visible: LongBool; Intent: TOCGIntent): Integer; stdcall; external 'LumasPdf.dll';
function pdfCreateOCGW(const IPDF: PPDF; const Name: PWideChar; DisplayInUI, Visible: LongBool; Intent: TOCGIntent): Integer; stdcall; external 'LumasPdf.dll';

TOCGIntent (from Lumas.Pdf.Types, bit values):

Delphi
TOCGIntent = Cardinal;
const oiDesign = 2; oiView = 4; oiAll = 8; oiEmpty = 16; oiVisible = 32;

Parameters

ParameterTypeDescription
IPDFPPDFInstance handle.
NamestringLayer name shown in a viewer's layer panel.
DisplayInUIBOOL32Accepted for ABI compatibility; not applied — see Remarks.
VisibleBOOL32Initial ON/OFF state — this one is real; drives both the current and default visibility.
IntentTOCGIntentAccepted for ABI compatibility; not applied — see Remarks.

Return value — 1-based OCG handle (> 0). This function cannot otherwise fail — it only appends to an in-memory table.

Remarks — compatibility parameters. DisplayInUI and Intent are accepted to match the reference ABI shape but are not stored or serialized; every OCG created here is discoverable in the display tree (subject to pdfDeleteOCGFromDisplayTree) and carries no per-OCG /Intent entry — only pdfCreateOCLayerConfig's Intent parameter reaches the file (as the alternate-configuration's /Intent). If your workflow depends on per-layer UI-visibility or intent flags, they are not representable through this call in the current engine.

See alsopdfBeginLayer, pdfChangeOCGName

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
public static extern int pdfCreateOCGA(IntPtr IPDF, [MarshalAs(UnmanagedType.LPStr)] string Name, [MarshalAs(UnmanagedType.Bool)] bool DisplayInUI, [MarshalAs(UnmanagedType.Bool)] bool Visible, uint Intent);
public static extern int pdfCreateOCGW(IntPtr IPDF, [MarshalAs(UnmanagedType.LPWStr)] string Name, [MarshalAs(UnmanagedType.Bool)] bool DisplayInUI, [MarshalAs(UnmanagedType.Bool)] bool Visible, uint Intent);
Area
Core SDK
Category

Object Creation

Exported names

pdfCreateOCGA pdfCreateOCGW

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.