[]
        
(Showing Draft Content)

Sound Annotation

A sound annotation is similar to a text annotation, but instead of displaying a text note, it contains an audio clip. The sound can be imported from an external file and played through the annotation icon on the page. The audio content is assigned through the sound property.

Sound-Annotation.png

Use the SoundAnnotation class to add sound annotations to a PDF document.

const doc = new PdfDocument();
const page = doc.newPage();

const rc = { x: 50, y: 50, width: 250, height: 50 };
const layout = new Layout({
    runs: [{
        text: "A red sound annotation is placed to the right of this note. Double click " +
            "the icon to play the sound.",
        font: Font.getPdfFont(StandardPdfFont.Times),
        fontSize: 11
    }],
    maxWidth: rc.width,
    maxHeight: rc.height
});
page.context.drawLayout(layout, rc.x, rc.y);

//Create an instance of SoundAnnotation class and set its relevant properties
const aiffAnnot = new SoundAnnotation();
aiffAnnot.userName = "Jaime Smith";
aiffAnnot.contents = "Sound annotation with an AIFF track.";
aiffAnnot.rect = { x: rc.x + rc.width, y: rc.y, width: 24, height: 24 };
aiffAnnot.icon = "Speaker";
aiffAnnot.color = "Red";
aiffAnnot.sound = new SoundObject(await Util.loadFile("sound/M1F1-AlawC-AFsp.aif"));

page.annotations.add(aiffAnnot);

const docData = doc.savePdf();
Util.saveFile("SoundAnnotation.pdf", docData);