Show / Hide Table of Contents

# Class Context

The OCG::Context object represents an optional-content context in a document, within which document objects such as words or annotations are visible or hidden. The context keeps track of the ON-OFF states of all of the optional-content groups (OCGs) in a document. Content is or is not visible with respect to the OCG states stored in a specific context. Unlike other objects in OCG namespace, the OCG::Context does not correspond to any explicit PDF structure.

Each PDFView has a default context (PDF::GetOCGContext()) that it uses for on-screen drawing and that determines the default state for any drawing. The context has flags that control whether to draw content that is marked as optional, and whether to draw content that is not marked as optional.

When enumerating page content, OCG::Context can be passed as a parameter in ElementReader.Begin() method. When using PDFDraw, PDFRasterizer, or PDFViewCtrl class to render PDF pages use SetOCGContext() method to select an OC context.

There can be more than one Context object, representing different combinations of OCG states. You can change the states of OCGs within any context. You can build contexts with your own combination of OCG states, and issue drawing or enumeration commands using that context. For example, you can pass an optional-content context to ElementReader.Begin(). You can save the resulting state information as part of the configuration (e.g. using Config::SetInit methods), but the context itself has no corresponding PDF representation, and is not saved.

##### Inheritance

object
Context

##### Implements

IDisposable

##### Inherited Members

object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()

###### Namespace: pdftron.PDF.OCG

###### Assembly: PDFTronDotNet.dll

##### Syntax

    public class Context : IDisposable

### Constructors

#### Context(Config)

Create a context object that represents an optional-content state of the document from a given configuration.

##### Declaration

    public Context(Config config)

##### Parameters

Type | Name | Description
--- | --- | ---
Config | config | A configuration from which to take initial OCG states.

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### Context(Context)

Copy constructor.

##### Declaration

    public Context(Context context)

##### Parameters

Type | Name | Description
--- | --- | ---
Context | context | Another context from which to take initial OCG states.

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

### Methods

#### Destroy()

##### Declaration

    public void Destroy()

#### Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

##### Declaration

    public void Dispose()

#### Dispose(bool)

##### Declaration

    protected virtual void Dispose(bool disposing)

##### Parameters

Type | Name | Description
--- | --- | ---
bool | disposing |

#### ~Context()

Releases all resources used by the Context

##### Declaration

    protected ~Context()

#### GetNonOCDrawing()

Gets the non oc drawing.

##### Declaration

    public bool GetNonOCDrawing()

##### Returns

Type | Description
--- | ---
bool | the non-OC status for this context. The flag indicates whether the content that is not marked as optional should be treated as visible. For more information, please see SetNonOCDrawing().

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### GetOCMode()

Gets OC drawing mode

##### Declaration

    public Context.OCDrawMode GetOCMode()

##### Returns

Type | Description
--- | ---
Context.OCDrawMode | OC drawing mode

#### GetState(Group)

Gets the state.

##### Declaration

    public bool GetState(Group group)

##### Parameters

Type | Name | Description
--- | --- | ---
Group | group | The optional-content group (OCG) that is queried.

##### Returns

Type | Description
--- | ---
bool | the ON-OFF states (true or false) for the given optional-content group (OCG) in this OC context.

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### ResetStates(bool)

Sets the states of all OCGs in the context to ON or OFF.

##### Declaration

    public void ResetStates(bool all_on)

##### Parameters

Type | Name | Description
--- | --- | ---
bool | all_on | A flag used to specify whether the OCG states should be set to ON (if true), or OFF (if false).

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### SetNonOCDrawing(bool)

Sets the non-OC status for this context. Content that is not marked as optional content is drawn (or element.IsOCVisible()) when 'draw_non_OC' is true, and not drawn/visible otherwise.

##### Declaration

    public void SetNonOCDrawing(bool draw_non_OC)

##### Parameters

Type | Name | Description
--- | --- | ---
bool | draw_non_OC | draw_non_OC A flag specifying whether the content that is not marked as optional should be treated as visible.

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### SetOCDrawMode(OCDrawMode)

Sets the drawing and enumeration type for this context. This type, together with the visibility determined by the OCG and OCMD states, controls whether content that is marked as optional content is drawn or enumerated.

##### Declaration

    public void SetOCDrawMode(Context.OCDrawMode oc_draw_mode)

##### Parameters

Type | Name | Description
--- | --- | ---
Context.OCDrawMode | oc_draw_mode | A flag specifying the visibility of optional content.

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

#### SetState(Group, bool)

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

##### Declaration

    public void SetState(Group group, bool state)

##### Parameters

Type | Name | Description
--- | --- | ---
Group | group | The optional-content group (OCG) that is queried.
bool | state | true for 'ON' and false for 'OFF'.

##### Exceptions

Type | Condition
--- | ---
PDFNetException | PDFNetException the PDFNet exception

### Implements

IDisposable