OptionalContentGroup
Overview
OptionalContentGroup is a class in Aspose.PDF FOSS for .NET.
Represents an Optional Content Group (layer) in a PDF document.
This class provides 9 methods for working with OptionalContentGroup objects in .NET programs.
Available methods include: AddContent, Delete, Flatten, Lock, OptionalContentGroup, Save, Unlock.
All public members are accessible to any .NET application after installing the Aspose.PDF FOSS for .NET package.
Properties: Contents, DefaultState, Id, Intent, IsLocked, IsVisible, and 2 more.
Properties
| Name | Type | Access | Description |
|---|---|---|---|
Name | string | Read | The layer name. |
Id | string? | Read | The OCG identifier used in page Resources/Properties (e.g. |
IsVisible | bool | Read/Write | Whether this layer is currently visible. |
IsLocked | bool | Read/Write | Whether this layer is locked (cannot be toggled by users). |
Locked | bool | Read/Write | Alias for IsLocked. |
DefaultState | DefaultState | Read/Write | The default visibility state of this layer. |
Intent | string? | Read | The intent of this layer (e.g., “View”, “Design”). |
Contents | IReadOnlyList<byte[]> | Read | Gets the content operators (as raw bytes) belonging to this layer from the page content stream (BDC/EMC markers) or from XForm streams that reference this layer’s OCG. |
Methods
| Signature | Description |
|---|---|
OptionalContentGroup(id: string, name: string) | Create a new layer with the given id and name. |
Lock() | Lock this layer so it cannot be toggled by users. |
Unlock() | Unlock this layer. |
Flatten(cleanupContentStream: bool) | Flatten this layer — remove the BDC/EMC markers but keep the content. |
Delete() | Delete this layer and all its content from the page. |
Save() | Save the content of this layer to a new single-page PDF document. |
Save(stream: Stream) | Save the content of this layer to a stream as a new single-page PDF. |
Save(outputPath: string) | Save the content of this layer to a file as a new single-page PDF. |
AddContent(op: Operators.Operator) | Add a content operator to this layer (for newly created layers). |