API referencePDF/A & Conformance

pdfAddLayerToDisplTree

pdfAddLayerToDisplTree builds a node in the OCG UI

C
void* __stdcall pdfAddLayerToDisplTreeA(PPDF IPDF, void* Parent, int32_t Layer, const char* Title);
BOOL32 __stdcall pdfAddObjectToLayer(PPDF IPDF, uint32_t OCG, TOCObject ObjType, uint32_t Handle);
Delphi
function pdfAddLayerToDisplTreeA(const IPDF: PPDF; Parent: Pointer; Layer: Integer; const Title: PAnsiChar): Pointer; stdcall;
function pdfAddObjectToLayer(const IPDF: PPDF; OCG: Cardinal; ObjType: TOCObject; Handle: Cardinal): LongBool; stdcall;

Purpose. pdfAddLayerToDisplTree builds a node in the OCG UI display tree (the "Layers" panel hierarchy a viewer shows, distinct from the OCGs themselves) — a labeled tree node optionally wrapping an actual OCG layer. pdfAddObjectToLayer associates an existing document object with an OCG so that object's visibility follows the layer.

Description. pdfAddLayerToDisplTree is real: stores the label, which real OCG layer (if any) this tree node represents, and its parent node (resolved from a 1-based node handle, or root if out of range), returning a new 1-based node handle wrapped as Pointer. Verified major limitation: pdfAddObjectToLayer's real implementation (AddObjectToLayer) only handles ObjType = 2 (images) — the case ObjType of 2: ... has no other branches and no else clause at all. Despite TOCObject's name implying multiple associable object kinds (annotations, form fields, XObjects/templates, content-stream marked content, etc. — the standard OCG-membership object types in the PDF spec), calling this with any ObjType other than the image kind is a silent no-op that returns False — only images can actually be tied to an OCG layer's visibility through this specific function.

Parameters.

ParameterDescription
IPDFDocument handle.
Parent*(DisplTree only)* Parent tree-node handle (as Pointer); out-of-range/invalid = root.
Layer*(DisplTree only)* The real OCG layer this node represents (or a sentinel for a label-only grouping node).
Title*(DisplTree only)* Node label.
OCG*(ObjectToLayer only)* Target OCG layer handle.
ObjType*(ObjectToLayer only)* Only the image object type is actually wired up — every other value silently fails.
Handle*(ObjectToLayer only)* The object handle to associate (must be a real image handle for this to succeed).

Return value. pdfAddLayerToDisplTree: the new node handle (as Pointer); nil on failure. pdfAddObjectToLayer: True only for a resolvable OCG and ObjType = ooImage with a resolvable image Handle; False for every other ObjType.

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
public static extern IntPtr pdfAddLayerToDisplTreeA(IntPtr IPDF, IntPtr Parent, int Layer, [MarshalAs(UnmanagedType.LPStr)] string Title);
public static extern IntPtr pdfAddLayerToDisplTreeW(IntPtr IPDF, IntPtr Parent, int Layer, [MarshalAs(UnmanagedType.LPWStr)] string Title);
Area
PDF/A & Conformance
Category

Content Creation

Exported names

pdfAddLayerToDisplTreeA pdfAddLayerToDisplTreeW

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.