Review, Markup, and Approval
Using Commenting Tools
7
Personalizing Attachments with a Description
To add a description to any annotation, set its
contents
property. In the case of file or
sound attachments, the property should be used to describe the contents of the
attachment, as shown in the code below:
this.addAnnot({
page: 0,
type: "Sound",
rect: [0,0,100,100],
name: "mySoundAnnot",
soundIcon: "mySound"
contents: "This is a sound file."
});
Opening and Saving Attachments
You may use Acrobat JavaScript to open any attachment. The general-purpose way to do
this is to invoke the
doc
object’s
getDataObjectContents
method. The following
code opens an attachment and displays its contents in the console:
var oFile = this.getDataObjectContents("MyAttachment");
var cFile = util.stringFromStream(oFile);
console.println(cFile);
To save and possibly open an attachment, invoke the
doc
object’s
exportDataObject
method. The method has an optional parameter called
nLaunch
which may be set to one
of three values:
0
(do not open, default),
1
(prompt the user for a save path, and open),
2
(do not prompt the user for a save path, and open). When using documents having
extensions other than PDF, include the extension in the file name. The method usage is
shown in the examples below:
// just save and do not open
this.exportDataObject("MyAttachment");
// save and open
this.exportDataObject({
cName: "MyComments.xls", nLaunch: 1}
);
Acrobat JavaScript Scripting Guide
131