4
Creating and Modifying PDF Documents
Creating and Modifying PDF Files
Extracting, Moving, Deleting, Replacing, and Copying Pages
The Acrobat JavaScript
doc
object, in combination with the
app
object, can be used to
extract pages from one document and place them in another, and moving or copying
pages within or between documents.
The
app
object an be used to create or open any document. To create a new document,
invoke its
newDoc
method, and to open an existing document, invoke its
openDoc
method.
The
doc
object offers three useful methods for handling pages:
●
●
●
insertPages
: inserts pages from the source document into the current document
deletePages
: deletes pages from the document
replacePages
: replaces pages in the current document with pages from the source
document.
These methods enable you to customize the page content within and between documents.
Suppose you would like to remove pages within a document. Invoke the
doc
object’s
deletePages
method, which accepts two parameters:
●
●
nStart
: the zero-based index of the beginning page
nEnd
: the zero-based index of the last page
For example, the following code deletes pages 2 through 5 of the current document:
this.deletePages({nStart: 2, nEnd: 5});
Suppose you would like to copy pages from one document to another. Invoke the
doc
object’s
insertPages
method, which accepts four parameters:
●
●
●
●
nPage
: the zero-based index of the page after which to insert the new pages
cPath
: the device-independent pathname of the source file
nStart
: the zero-based index of the beginning page
nEnd
: the zero-based index of the last page
For example, the following code inserts pages 2 through 5 from
mySource.pdf
at the
beginning of the current document:
this.insertPages({
nPage: -1,
cPath: "/C/mySource.pdf",
nStart: 2,
nEnd: 5
});
72
Acrobat JavaScript Scripting Guide