7
Review, Markup, and Approval
Using Commenting Tools
Adding Attachments
You may use Acrobat JavaScript to embed sound clips, images, and files within comments.
The Acrobat support for sound and file attachments within comments is available through
the
annot
object’s
Sound
and
FileAttachment
types. Also, you may pass an
Icon
Stream Generic Object
as an optional property (
oIcon
) of the
oStates
object literal used
in the
Collab
object’s
addStateModel
method.
Sound Attachments
To add a sound attachment using Acrobat JavaScript, invoke the
doc
object’s
importSound
method to attach the sound file to the PDF. Then create an annotation
using the
doc
object’s
addAnnot
method, and associate the
Sound
object with the
annotation by assigning the name of the
Sound
object to the
annot
object’s
soundIcon
property. An example is given below:
// Attach the sound file to the PDF file
this.importSound("mySound", "/C/mySound.wav");
// Create the annotation and assign its
soundIcon
property
this.addAnnot({
page: 0,
type: "Sound",
rect: [0,0,100,100],
name: "mySoundAnnot",
soundIcon: "mySound"
});
File Attachments
To add a file attachment to a document, invoke one of the
doc
object’s
import
methods,
such as
importDataObject
. Once the file contents have been imported they can be
accessed using such methods as
getDataObject
, and either merged with your
document content or saved to a disk location. For example, the following code imports the
contents of
myFile.xml
and displays its contents:
// Open the file attachment named myFile.xml
this.importDataObject(myData, "/C/myFile.xml");
// Access its contents:
var contents = this.getDataObject("myData");
// Display its contents:
for (var i in contents) console.println(contents[i]);
To create an attachment annotation, set the
annot
object’s
attachIcon
property. At this
point, you may decide how to associate the attachment’s name with the icon.
130
Acrobat JavaScript Scripting Guide