# OptionalContentContext Class

> Defines the context for optional content in a PDF.

- Product: Adobe PDF Library 21
- Language: .NET Framework
- Version: APDFL21.0.0PlusP1e
- HTML page: https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/OptionalContentContext
- Version index: https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/llms.txt

```csharp
class OptionalContentContext : SystemIDisposable
```

**Namespace:** `Datalogics::PDFL`

**Inherits from:** `SystemIDisposable`

## Description

Defines the context for optional content in a PDF.

An Optional Content Context is a status object that defines the context for optional content within a document.

The context tracks the On/Off status for Optional Content Groups (layers) within a document. It contains flags that control whether to display content that is marked as optional.

**Referenced by:** [`Annotation`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Annotation.md), [`CircleAnnotation`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/CircleAnnotation.md), [`Container`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Container.md), [`Content`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Content.md), [`Document`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Document.md), [`DrawParams`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/DrawParams.md), [`Form`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Form.md), [`FreeTextAnnotation`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/FreeTextAnnotation.md), [`HighlightAnnotation`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/HighlightAnnotation.md), [`InkAnnotation`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/InkAnnotation.md), [`LineAnnotation`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/LineAnnotation.md), [`LinkAnnotation`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/LinkAnnotation.md), [`OptionalContentContext`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/OptionalContentContext.md), [`Page`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Page.md), [`PolyLineAnnotation`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/PolyLineAnnotation.md), [`PolygonAnnotation`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/PolygonAnnotation.md), [`PrintParams`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/PrintParams.md), [`Redaction`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Redaction.md), [`SeparationParams`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/SeparationParams.md), [`SquareAnnotation`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/SquareAnnotation.md), [`TextMarkupAnnotation`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/TextMarkupAnnotation.md), [`UnderlineAnnotation`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/UnderlineAnnotation.md)

**Uses types:** [`Document`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Document.md), [`OptionalContentContext`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/OptionalContentContext.md), [`OptionalContentDrawingPolicy`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/enum/OptionalContentDrawingPolicy.md), [`OptionalContentGroup`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/OptionalContentGroup.md)

## Constructors

### OptionalContentContext

```csharp
Datalogics.PDFL.OptionalContentContext.OptionalContentContext(Document document)
```

*constructor*

**Parameters**

- `document` ([`Document`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/Document.md)): The document for which to create a context.

Creates a context object that represents an optional-content state of the document, using the current state as the initial state for each group (OCG), as determined by the document's optional-content configuration.

## Properties

### DrawOptionalContent

```csharp
OptionalContentDrawingPolicy Datalogics.PDFL.OptionalContentContext.DrawOptionalContent { get; set; }
```

Gets the drawing policy for the optional content in this optional content context.

## Methods

### Clone

```csharp
OptionalContentContext Datalogics.PDFL.OptionalContentContext.Clone()
```

**Returns:** [`OptionalContentContext`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/OptionalContentContext.md)

A copy of the original optional content context.

Makes a copy of the optional content context.

### Dispose

```csharp
void Datalogics.PDFL.OptionalContentContext.Dispose()
```

**Returns:** `void`

### Equals

```csharp
override bool Datalogics.PDFL.OptionalContentContext.Equals(object obj)
```

**Parameters**

- `obj` (`object`)

**Returns:** `override bool`

### GetOCGStates

```csharp
System.Collections.Generic.IList< System.Boolean > Datalogics.PDFL.OptionalContentContext.GetOCGStates(System.Collections.Generic.IList< OptionalContentGroup > ocgs)
```

**Parameters**

- `ocgs` ([`System.Collections.Generic.IList< OptionalContentGroup >`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/OptionalContentGroup.md)): A list of optional-content groups whose states are obtained.

**Returns:** `System.Collections.Generic.IList< System.Boolean >`

An array of OCG states corresponding to the array of OCGs, true for ON and false for OFF.

Gets the ON-OFF states for the given optional-content groups (OCGs) in the given optional-content context.

### GetStateOfOCG

```csharp
bool Datalogics.PDFL.OptionalContentContext.GetStateOfOCG(OptionalContentGroup ocg)
```

**Parameters**

- `ocg` ([`OptionalContentGroup`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/OptionalContentGroup.md)): The optional content group whose state will be retrieved.

**Returns:** `bool`

true if the OCG is ON, false if it is OFF.

Gets the ON-OFF state for the given optional content group (OCG) in this optional content context.

### SetOCGStates

```csharp
void Datalogics.PDFL.OptionalContentContext.SetOCGStates(System.Collections.Generic.IList< OptionalContentGroup > ocgs, System.Collections.Generic.IList< System.Boolean > newStates)
```

**Parameters**

- `ocgs` ([`System.Collections.Generic.IList< OptionalContentGroup >`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/OptionalContentGroup.md)): A list of optional-content groups.
- `newStates` (`System.Collections.Generic.IList< System.Boolean >`): A list of new OCG states corresponding to the list of OCGs, true for ON and false for OFF. The list must contain as many states as there are non-NULL OCGs in the pdocgs list.

**Returns:** `void`

Sets the ON-OFF states for the given optional-content groups (OCGs) in the given optional-content context. The newStates vector must be large enough to hold as many Boolean values as there are OCGs.

### SetStateOfOCG

```csharp
void Datalogics.PDFL.OptionalContentContext.SetStateOfOCG(OptionalContentGroup ocg, bool newValue)
```

**Parameters**

- `ocg` ([`OptionalContentGroup`](https://docs.datalogics.com/apdfl21/DotNetFramework/APDFL21.0.0PlusP1e/class/OptionalContentGroup.md)): The optional content group whose state will be set.
- `newValue` (`bool`): The new ON-OFF state for the optional content group.

**Returns:** `void`

Sets the ON-OFF state for the given optional content group (OCG) in this optional content context.

### ToString

```csharp
override string Datalogics.PDFL.OptionalContentContext.ToString()
```

**Returns:** `override string`

A string describing the state of all optional content groups in this context.

Returns a string representation of this OptionalContentContext.

The string lists all optional content groups in the document along with their ON/OFF states in this context.
