Class: OCGContext

PDFNet. OCGContext


new OCGContext()

The OCGContext 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 OCGContext 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, OCGContext can be passed as a parameter in ElementReader.Begin() method. When using PDFDraw, PDFRasterizer, or PDFView class to render PDF pages use ( PDFDraw::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.

Extends

Members


<static> OCDrawMode

Type:
  • number
Properties:
Name Type Description
e_VisibleOC number
e_AllOC number
e_NoOC number

Methods


<static> createFromConfig(cfg)

Create a context object that represents an optional-content state of the document from a given configuration.
Parameters:
Name Type Description
cfg PDFNet.OCGConfig A configuration from which to take initial OCG states.
Returns:
A promise that resolves to an object of type: "PDFNet.OCGContext"
Type
Promise.<PDFNet.OCGContext>

copy()

Copy Constructor
Returns:
A promise that resolves to an object of type: "PDFNet.OCGContext"
Type
Promise.<PDFNet.OCGContext>

destroy()

Destructor
Inherited From:
Returns:
Type
Promise.<void>

getNonOCDrawing()

Returns:
A promise that resolves to 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().
Type
Promise.<boolean>

getOCMode()

Returns:
A promise that resolves to the drawing and enumeration type for this context. For more information, please see SetOCMode() and OCG::Context::OCDrawMode.
Type
Promise.<number>
Example
Return value enum:
<pre>
PDFNet.OCGContext.OCDrawMode = {
	e_VisibleOC : 0
	e_AllOC : 1
	e_NoOC : 2
}
</pre>

getState(grp)

Parameters:
Name Type Description
grp PDFNet.OCG The optional-content group (OCG) that is queried.
Returns:
A promise that resolves to the ON-OFF states (true or false) for the given optional-content group (OCG) in this OC context.
Type
Promise.<boolean>

resetStates(all_on)

Sets the sates of all OCGs in the context to ON or OFF.
Parameters:
Name Type Description
all_on boolean A flag used to specify whether the OCG states should be set to ON (if true), or OFF (if false).
Returns:
Type
Promise.<void>

setNonOCDrawing(draw_non_OC)

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.
Parameters:
Name Type Description
draw_non_OC boolean A flag specifying whether the content that is not marked as optional should be treated as visible.
Returns:
Type
Promise.<void>

setOCDrawMode(oc_draw_mode)

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.
Parameters:
Name Type Description
oc_draw_mode number
PDFNet.OCGContext.OCDrawMode = {
	e_VisibleOC : 0
	e_AllOC : 1
	e_NoOC : 2
}
A flag specifying the visibility of optional content.
Returns:
Type
Promise.<void>

setState(grp, state)

Sets the ON-OFF states for the given optional-content group (OCG) in this context.
Parameters:
Name Type Description
grp PDFNet.OCG The optional-content group (OCG) that is queried.
state boolean true for 'ON' and false for 'OFF'.
Returns:
Type
Promise.<void>

takeOwnership()

Take the ownership of this object, so that PDFNet.runWithCleanup won't destroy this object.
Inherited From:
Returns:
Type
void