4
Creating and Modifying PDF Documents
Creating and Modifying PDF Files
The following example moves pages 2-5 after page 30 in the document:
// First create the temporary document:
var tempDoc = app.newDoc("/C/temp.pdf");
// Copy pages 2-5 into the temporary file
tempDoc.insertPages({
cPath: "/C/mySource.pdf",
nStart: 2,
nEnd: 5
});
// Copy all of the temporary file pages back into the original:
this.insertPages({
nPage: 30,
cPath: "/C/temp.pdf"
});
// Now delete pages 2-5 from the source document
this.deletePages({nStart: 2, nEnd: 5});
Adding Watermarks and Backgrounds
The
doc
object’s
addWatermarkFromText
and
addWatermarkFromFile
methods
create watermarks within a document, and place them in optional content groups (OCGs).
The
addWatermarkFromFile
method adds a page as a watermark to the specified
pages in the document. The example below adds the first page of
watermark.pdf
as a
watermark to the center of all pages within the current document:
this.addWatermarkFromFile("/C/watermark.pdf");
In the next example, the
addWatermarkFromFile
method is used to add the second
page of
watermark.pdf
as a watermark to the first 10 pages of the current document. It is
rotated counterclockwise by 45 degrees, and positioned one inch down and two inches
over from the top left corner of each page:
this.addWatermarkFromFile({
cDIPath: "/C/watermark.pdf",
nSourcePage: 1,
nEnd: 9,
nHorizAlign: 0,
nVertAlign: 0,
nHorizValue: 144,
nVertValue: -72,
nRotation: 45
});
74
Acrobat JavaScript Scripting Guide