OCG
OCG (Optional Content Group) object represents layers in a PDF file. OCGs control the visibility of content and are referred to as "Layers" within Revu. OCG objects are obtained through the Doc.getOCGs method.
properties
constants
Secure | Type | Access |
---|---|---|
No | object | R |
Object containing constants used with OCG operations.
Properties of the constants object:
Property | Type | Description |
---|---|---|
intents | object | Intent constants for OCG purposes |
states | object | State constants for OCG visibility |
intents
Properties of the intents object:
Property | Value | Description |
---|---|---|
design | "Design" | Content for design purposes |
view | "View" | Content for interactive viewing |
states
Properties of the states object:
Property | Value | Description |
---|---|---|
on | true | Layer is visible |
off | false | Layer is hidden |
example:
var ocgs = this.getOCGs()
if (ocgs != null && ocgs.length > 0) {
var ocg = ocgs[0]
console.println(ocg.constants.intents.view) // Prints "View"
console.println(ocg.constants.states.on) // Prints true
}
initState
Secure | Type | Access |
---|---|---|
No | boolean | R/W |
The initial state of the OCG when the document is first opened. When true, the layer is visible by default. When false, the layer is hidden by default.
example:
var ocgs = this.getOCGs()
if (ocgs != null) {
ocgs.forEach(function(ocg) {
if (ocg.name === "Electrical") {
ocg.initState = false // Hide electrical layer by default
}
})
}
locked
Secure | Type | Access |
---|---|---|
No | boolean | R/W |
Specifies whether the OCG is locked. When locked, users cannot change the visibility state of the layer through the Revu interface.
example:
var ocgs = this.getOCGs()
if (ocgs != null) {
ocgs.forEach(function(ocg) {
if (ocg.name === "Watermark") {
ocg.locked = true // Prevent users from hiding the watermark
}
})
}
name
Secure | Type | Access |
---|---|---|
No | string | R/W |
The name of the OCG as it appears in the Layers panel.
example:
var ocgs = this.getOCGs()
if (ocgs != null) {
ocgs.forEach(function(ocg, index) {
console.println(`Layer ${index}: ${ocg.name}`)
// Rename a specific layer
if (ocg.name === "Layer1") {
ocg.name = "Structural"
}
})
}
state
Secure | Type | Access |
---|---|---|
No | boolean | R/W |
The current visibility state of the OCG. When true, the layer is visible. When false, the layer is hidden.
example:
var ocgs = this.getOCGs()
if (ocgs != null) {
// Toggle all layers
ocgs.forEach(function(ocg) {
ocg.state = !ocg.state
})
// Hide all layers except one
ocgs.forEach(function(ocg) {
ocg.state = (ocg.name === "Architectural")
})
}
methods
getIntent
Secure |
---|
No |
Returns the intent setting for the OCG.
getIntent()
Returns an array of strings representing the intent(s) of the OCG. Possible values are "View" and "Design".
The intent determines the purpose of the OCG:
- "View": Content intended for interactive viewing
- "Design": Content intended for design purposes
An OCG can have multiple intents.
example:
var ocgs = this.getOCGs()
if (ocgs != null && ocgs.length > 0) {
var ocg = ocgs[0]
var intents = ocg.getIntent()
console.println("OCG intents: " + intents.join(", "))
// Check if OCG has view intent
if (intents.indexOf("View") !== -1) {
console.println("This layer is intended for viewing")
}
}
setIntent
Secure |
---|
No |
Sets the intent for the OCG.
setIntent(aIntents)
aIntents: Array of intent strings. Valid values are "View" and "Design".
example:
var ocgs = this.getOCGs()
if (ocgs != null) {
ocgs.forEach(function(ocg) {
if (ocg.name === "Annotations") {
// Set layer for both viewing and design
ocg.setIntent(["View", "Design"])
} else if (ocg.name === "Guidelines") {
// Set layer for design only
ocg.setIntent(["Design"])
}
})
}