SoundAnnotation Class
Defines a PDF sound annotation.
Declaration
public class SoundAnnotation extends MarkupAnnotation
Remarks
A sound annotation embeds an audio clip into a PDF document and displays an icon that users can click to play the sound in a compatible PDF viewer.
Use the SoundAnnotation class to create a sound annotation. Specify annotation bounds, assign a Sound object that contains the audio data, and optionally change the annotation icon.
The following code snippet creates a sound annotation and embeds a WAV audio file:

static void createSoundAnnotation(Page page) {
SoundAnnotation annotation =
new SoundAnnotation(
new RectangleF(50, 420, 20, 20));
annotation.setTitle("John Smith");
annotation.setContent("Voice note");
annotation.setIconName(SoundAnnotationIconName.MIC);
try {
Sound sound = new Sound();
sound.setSamplingRate(44100);
sound.setSoundChannels(2);
sound.setBitsPerSample(16);
sound.setEncoding(SoundEncoding.RAW);
sound.setData(Files.readAllBytes(Path.of("VoiceNote.wav")));
annotation.setSound(sound);
page.getAnnotations().add(annotation);
} catch (IOException e) {
throw new UncheckedIOException("Failed to read the audio file.", e);
}
}
Refer to the following help topic for additional information: File and Multimedia Annotations.
Inherited Members
Inheritance
SoundAnnotation(RectangleF bounds)
Initializes a new instance of the SoundAnnotation class with specified bounds.
Declaration
public SoundAnnotation(RectangleF bounds)
Parameters
| Name | Type | Description |
|---|---|---|
| bounds | RectangleF | The sound annotation bounds. |
Methods
getIconName() Method
Returns the sound annotation icon name.
Declaration
public SoundAnnotationIconName getIconName()
Returns
| Type | Description |
|---|---|
| SoundAnnotationIconName | The sound annotation icon name. |
getSound() Method
Returns the sound annotation sound.
Declaration
public Sound getSound()
Returns
| Type | Description |
|---|---|
| Sound | The sound annotation sound. |
setIconName(SoundAnnotationIconName value) Method
Sets the sound annotation icon name.
Declaration
public void setIconName(SoundAnnotationIconName value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | SoundAnnotationIconName | The sound annotation icon name. |
setSound(Sound value) Method
Sets the sound annotation sound.
Declaration
public void setSound(Sound value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | Sound | The sound annotation sound. |