Review, Markup, and Approval
Managing Comments
7
Exporting and Importing Comments
To use Acrobat JavaScript to export all the comments in a file, invoke the
doc
object’s
exportAsFDF
or
exportAsXFDF
methods. In both cases, set the
bAnnotations
parameter to
true
, as shown in the code sample below, which exports only the comments
and nothing else:
this.exportAsFDF({bAnnotations: true});
To use Acrobat JavaScript to import comments from an FDF or XFDF into a file, invoke the
doc
object’s
importAnFDF
or
importAnXFDF
methods.
Comparing Comments in Two PDF Documents
While the Acrobat user interface provides you with a menu choice for comparing two
documents, it is possible to customize your comparisons using Acrobat JavaScript. To gain
access to multiple documents, invoke the
app
object’s
openDoc
method for each
document you would like to analyze. Each
doc
object exposes the contents of each
document, such as an array of annotations. You may then compare and report any
information using customized algorithms. For example, the code below reports how many
annotations exist in the two documents:
var doc2 = app.openDoc("/C/secondDoc.pdf");
var annotsDoc1 = this.getAnnots();
var annotsDoc2 = doc2.getAnnots();
console.println("Doc 1: " + annotsDoc1.length + " annots.");
console.println("Doc 2: " + annotsDoc2.length + " annots.");
Aggregating Comments for Use in Excel
The
doc
object’s
exportDataObject
method may be used to create a tab-delimited
text file, which can then be used in Excel. To use Acrobat JavaScript to aggregate comments
for use in Excel, collect all the comments using the
doc
object’s
getAnnots
method,
iterate through them and save them into a tab-delimited string, create a text file
attachment object using the
doc
object’s
createDataObject
method, and pass the
string to the
cValue
parameter in the
exportDataObject
method.
Extracting Comments in a Batch Process
In a batch process, you may open any number of
doc
objects using the
app
object’s
openDoc
method. For each open document, you may invoke its corresponding
doc
object’s
getAnnots
method to collect the comments in that file. If you would like to put
all the comments together in one file, you may do so by creating a new document and
saving the various arrays of comments into that new file.
Acrobat JavaScript Scripting Guide
139