Modifying the User Interface
Working with PDF Layers
10
Working with PDF Layers
About PDF Layers
PDF layers are components of content that may occupy the same space as other
components. Multiple components may be visible or invisible depending on their settings,
and may be used to support the display, navigation, and printing of layered PDF content by
various applications. It is possible to edit the properties of layers, lock layers, add navigation
to them, merge or flatten layers, and combine PDF layered documents. PDF layers are
supported through the usage of Acrobat JavaScript Optional Content Group (OCG) objects.
To obtain an array of the
OCG
objects for a given page in the document, invoke the
doc
object’s
getOCGs
method. The following code obtains the array of OCG objects contained
on page 3 of the document:
var ocgArray = this.getOCGs(3);
Navigating with Layers
Since information can be stored in different layers of a PDF document, navigational controls
can be customized within different layers, whose visibility settings may be dynamically
customized so that they are tied to context and user interaction. For example, if the user
selects a given option, a set of navigational links belonging to a corresponding optional
content group may be shown.
In addition, it is possible to determine the order in which layers are displayed in the user
interface by invoking the
doc
object’s
getOCGOrder
and
setOCGOrder
methods. In
the following example, the display order of all the layers is reversed:
var ocgOrder = this.getOCGOrder();
var newOrder = new Array();
for (var i=0; i<ocgOrder.length; i++)
newOrder[i] = ocgOrder[ocgOrder.length - i - 1];
this.setOCGOrder(newOrder);
Acrobat JavaScript Scripting Guide
187