4
Creating and Modifying PDF Documents
Creating and Modifying PDF Files
If you would like to automate the insertion of multiple PDF files into a single PDF
document, you may do so through a series of calls to the
doc
object’s
insertPages
and
replacePages
methods. For example, the following code inserts a cover page at the
beginning of the current document:
this.insertPages({
nPage : -1,
cPath : "/c/myCoverPage.pdf",
nStart: 0
});
Finally, if you would like to use a portion of the current document to create a new
document, you may do so by invoking the
doc
object’s
extractPages
method. For
example, suppose the document consists of a sequence of invoices, each of which occupies
one page. The following code creates separate PDF files, one for each invoice:
var filename = "invoice";
for (var i = 0; i < this.numPages; i++)
this.extractPages({
nStart: i,
cPath : filename + i + ".pdf"
});
Cropping and Rotating Pages
Cropping Pages
The Acrobat JavaScript
doc
object provides methods for setting and retrieving the page
layout dimensions. These are the
setPageBoxes
and
getPageBox
methods. There are
five types of boxes available:
●
●
●
●
●
Art
Bleed
Crop
Media
Trim
The
setPageBoxes
method accepts the following parameters:
●
●
●
●
cBox
: the type of box
nStart
: the zero-based index of the beginning page
nEnd
: the zero-based index of the last page
rBox
: the rectangle in rotated user space
70
Acrobat JavaScript Scripting Guide