Modifying the User Interface
Working with PDF Layers
10
The
name
property represents the text string seen in the user interface that is used to
identify layers. In the following example, the
Watermark
OCG is toggled:
var ocgs = this.getOCGs();
for (var i=0; i<ocgs.length; i++)
if (ocgs[i].name == "Watermark")
ocgs[i].state = !ocgs[i].state;
Merging Layers
You can use Acrobat JavaScript to merge layers in a PDF document. A merged layer (the
source layer) will acquire the properties of the layer into which they are merged (the target
layer). In the following example,
sourceLayer
is merged into
targetLayer
:
sourceLayer.initState = targetLayer.initState;
sourceLayer.intent = targetLayer.intent;
sourceLayer.locked = targetLayer.locked;
sourceLayer.name = targetLayer.name;
sourceLayer.state = targetLayer.state;
Flattening PDF Layers
Flattening layers means that they will be consolidated. This operation is done through the
Layers
tab in the user interface.
Combining PDF Layered Documents
Multiple PDF documents containing layers can be combined while preserving the layered
information. When doing this, it may be necessary to rearrange the order of the merged
OCG arrays. To accomplish this, obtain the OCG order arrays for each document, and merge
them into a new array in the merged document. In the example shown below,
source1.pdf
and
source2.pdf
are combined into
target.pdf
. It is assumed that there are
no common layers between the two documents:
Acrobat JavaScript Scripting Guide
189