File and Multimedia Annotations
- 4 minutes to read
File Attachment Annotations
A file attachment annotation embeds a file into a PDF document and displays an icon that users can click to open or extract the attached file.
Use the FileAttachmentAnnotation class to create a file attachment annotation.
Customize the Annotation Icon
Use the FileAttachmentAnnotation.IconName property to specify the icon displayed for the attachment.
The PDF Document API supports the following icon names:
- Push Pin (default)
- Graph
- Paper Clip
- Tag
Attach a File
Use the FileAttachmentAnnotation.FileSpecification property to attach a file to the annotation.
Create a FileSpecification object, specify the file name, load the file data, and assign the file specification to the annotation.
Example: Create a File Attachment Annotation
The following code snippet creates a file attachment annotation and embeds a text file:

using DevExpress.Docs.Pdf;
using System.Drawing;
using (PdfDocument pdfDocument =
new PdfDocument(File.OpenRead(@"Document.pdf")))
{
// Create a file attachment annotation
FileAttachmentAnnotation annotation =
new FileAttachmentAnnotation(
new RectangleF(50, 420, 20, 20));
annotation.Content = "Project specification";
annotation.Title = "John Smith";
annotation.IconName = FileAttachmentAnnotationIconName.PaperClip;
// Create a file data for the attachment
FileSpecification fileSpecification = new FileSpecification();
fileSpecification.FileName = "Specification.pdf";
fileSpecification.FileData = File.ReadAllBytes(Path.Combine(Directory.GetCurrentDirectory(), "Specification.pdf"));
fileSpecification.Description = "Project specification";
annotation.FileSpecification = fileSpecification;
// Add the annotation to the first page of the PDF document
pdfDocument.Pages[0].Annotations.Add(annotation);
pdfDocument.Save(File.OpenWrite(@"DocumentWithAnnotation.pdf"));
}
Sound Annotations
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.
Attach Audio Data
Use the SoundAnnotation.Sound property to associate audio data with the annotation.
Create a Sound object, configure the audio format, load the sound data, and assign the object to the annotation.
Configure the Sound object to match the format of the embedded audio file. For example, an uncompressed CD-quality WAV file uses a sampling rate of 44,100 Hz, two channels (stereo), 16 bits per sample, and SoundEncoding.RAW.
Customize the Annotation Icon
Use the SoundAnnotation.IconName property to specify the icon displayed for the sound annotation.
The PDF Document API supports the following icon names:
- Speaker (default)
- Microphone
- Headphone
Example: Create a Sound Annotation
The following code snippet creates a sound annotation and embeds a WAV audio file:

using DevExpress.Docs.Pdf;
using System.Drawing;
using (PdfDocument pdfDocument =
new PdfDocument(File.OpenRead(@"Document.pdf")))
{
// Create a sound annotation
SoundAnnotation annotation =
new SoundAnnotation(
new RectangleF(50, 420, 20, 20));
annotation.Title = "John Smith";
annotation.Content = "Voice note";
annotation.IconName = SoundAnnotationIconName.Mic;
// Load sound data from a WAV file
Sound sound = new Sound();
sound.SamplingRate = 44100;
sound.SoundChannels = 2;
sound.BitsPerSample = 16;
sound.Encoding = SoundEncoding.Raw;
sound.Data = File.ReadAllBytes(Path.Combine(Directory.GetCurrentDirectory(), "VoiceNote.wav"));
annotation.Sound = sound;
// Add the annotation to the first page of the PDF document
pdfDocument.Pages[0].Annotations.Add(annotation);
pdfDocument.Save(File.OpenWrite(@"DocumentWithAnnotation.pdf"));
}