Creating and Modifying PDF Documents
Creating and Modifying PDF Files
4
Combining PDF Documents
You can take advantage of Acrobat JavaScript to customize and automate the process of
combining PDF documents.
If you would like to combine multiple PDF files into a single PDF document, you may do so
through a series of calls to the
doc
object’s
insertPages
method. For example, the
following code creates a new document that is composed from two other documents:
// Create a new PDF document:
var newDoc = app.newDoc();
// Insert doc1.pdf:
newDoc.insertPages({
nPage : -1,
cPath : "/c/doc1.pdf",
});
// Insert doc2.pdf:
newDoc.insertPages({
nPage : newDoc.numPages,
cPath : "/c/doc2.pdf",
});
// Save the new document:
newDoc.saveAs({
"/c/myNewDoc.pdf");
});
// Close the new document without notifying the user:
newDoc.closeDoc(true);
Creating PDF Files from Multiple Files
It is possible to dynamically add content from other sources into a new PDF file. The sources
may include files whose types conform to Multipurpose Internet Mail Extensions (MIME
®
)
type definitions. One simple approach would be to invoke the
app
object’s
openDoc
method to convert and open other files with supported formats, and then save or combine
files as a PDF document.
Another way to import an external file into a PDF document is to invoke the
doc
object’s
importDataObject
method. After doing this, it is possible to extract information from
the external file for placement and presentation within the PDF document. For example,
the following code illustrates how to import an XML file and extract its content:
this.importDataObject("myFile", "/c/myFile.xml");
var myData = this.getDataObject("myFile");
for (var i in myData)
console.println(myData[i]);
Acrobat JavaScript Scripting Guide
69