[]
        
(Showing Draft Content)

Sound Actions

Sound action is an interactive feature that plays an audio file when interacting with a PDF document. You can interact by clicking a button, hovering over an area, or other user-triggered events in the document. DsPdf provides ActionSound class and its properties that enable you to define sound action in a PDF document. The following table lists all the properties of ActionSound class:

Property

Description

Sound

Sets the SoundObject object defining the sound to play.

Volume

Sets the volume at which the sound is played. The range is -1.0 to 1.0.

Synchronous

Sets the value specifying whether to play the sound synchronously or asynchronously. If true, the interactive PDF processor retains control, allowing no further user interaction other than canceling the sound, until the sound has been completely played. The default value is false.

Repeat

Sets the value specifying whether to repeat the sound indefinitely. If this property is set, DsPdf will ignore Synchronous property. The default value is false.

Mix

Sets the value specifying whether to mix this sound with any other sound already playing. If false, any previously playing sound will stop before starting this sound; this can be used to stop a repeating sound. The default value is false.

Refer to the following example code to add sound action to the PDF document:

// Initialize GcPdfDocument.
var doc = new GcPdfDocument();

// Add a blank page to the document.
var page = doc.NewPage();

// Get an instance of GcPdfGraphics.
var g = page.Graphics;

// Add a push button to the document.
PushButtonField btn = new PushButtonField();

// Set page for the button.
btn.Widget.Page = page;
btn.Widget.Rect = new RectangleF(10, 10, 150, 30);

// Set caption of the button.
btn.Widget.ButtonAppearance.Caption = "Alarm";

// Add sound action.
btn.Widget.Events.MouseDown = new ActionSound(SoundObject.FromFile(Path.Combine("Alarm01.wav")));

// Add the button.
doc.AcroForm.Fields.Add(btn);

// Save the document.
doc.Save("ActionSound.pdf");


Limitations

Adobe Acrobat ignores Volume property of ActionSound class.