10
Modifying the User Interface
Working with PDF Layers
// Open the source documents:
var source1 = app.openDoc("/C/source1.pdf");
var source2 = app.openDoc("/C/source2.pdf");
// Obtain the OCG order array for each source document:
var mergedOCGArray = new Array();
var source1OCGArray = source1.getOCGOrder();
var source2OCGArray = source2.getOCGOrder();
// Merge the OCG order arrays into the target array:
for (var i=0; i<source1OCGArray.length; i++)
mergedOCGArray[i] = source1OCGArray[i];
var offset = source1OCGArray.length;
for (var j=0; j<source2OCGArray.length; j++)
mergedOCGArray[offset + j] = source2OCGArray[j];
// Create the target document:
var target = app.newDoc("/C/target.pdf");
// Insert source1.pdf:
target.insertPages({
nPage : -1,
cPath : "/c/source1.pdf",
});
// Insert source2.pdf:
target.insertPages({
nPage : target.numPages,
cPath : "/c/source2.pdf",
});
// Set the OCG order array in the target document
target.setOCGOrder(mergedOCGArray);
// Save the target document:
target.saveAs({
"/c/target.pdf");
});
// Close the target document without notifying the user:
target.closeDoc(true);
190
Acrobat JavaScript Scripting Guide