Sound annotation is analogous to a text annotation except that instead of a text note, it contains sound (.au, .aiff, or .wav format) imported from a file or recorded from the computer’s microphone. DsPdf provides SoundAnnotation class to enable users to apply sound annotations to the PDF file.
SoundAnnotation class provides the following properties to set various options for the sound annotation:
Property | Description |
---|---|
UserName | Adds the user name to the text label in the title bar of the annotation’s pop-up window when the annotation is open and active. |
Subject | Adds the text representing the subject of the annotation. |
Contents | Adds the text to the annotation for display. |
RichText | Adds the text to the annotation for display in the pop-up window when opened. You can format this text using HTML tags. |
Opacity | Sets the opacity of the annotation. |
Color | Sets the annotation color, popup window color, line color, etc. |
Sound | Sets the sound to be played when the annotation is activated. |
Icon | Sets the type of icon used to display the annotation. |
PdfRect | Sets the rectangle that defines the location and size of the annotation on a page in PDF user space coordinates. The positive X axis extends horizontally to the right, and the positive Y axis extends vertically upward, with the origin usually in the lower left corner of the page. |
Refer to the following example code to add a sound annotation to a PDF document:
C# |
Copy Code
|
---|---|
public void CreateSoundAnnotation() { GcPdfDocument doc = new GcPdfDocument(); Page page = doc.NewPage(); RectangleF rc = new RectangleF(50, 50, 250, 50); page.Graphics.DrawString("A red sound annotation is placed to the right of this note. Double click " + "the icon to play the sound.", new TextFormat() { Font = StandardFonts.Times, FontSize = 11 }, rc); //Create an instance of SoundAnnotation class and set its relevant properties var aiffAnnot = new SoundAnnotation() { UserName = "Jaime Smith", Contents = "Sound annotation with an AIFF track.", PdfRect = new RectangleF(rc.Right, rc.Top, 24, 24), Icon = SoundAnnotationIcon.Speaker, Color = Color.Red, Sound = SoundObject.FromFile(Path.Combine("Resources", "Sounds", "ding.aiff"), AudioFormat.Aiff) }; page.Annotations.Add(aiffAnnot); doc.Save("SoundAnnotation.pdf"); } |