Pdf - PdfSoundAction

18 Nov 20269 minutes to read

Represents an action that plays an embedded sound resource.

// Create a new PDF document
let document: PdfDocument = new PdfDocument();
let page: PdfPage = document.addPage();
// Create and configure a sound resource
let sound: PdfSound = new PdfSound(soundData);
sound.bits = 16;
sound.channels = PdfSoundChannels.Stereo;
sound.encoding = PdfSoundEncoding.Signed;
sound.rate = 44100;
// Create a sound action
let action: PdfSoundAction = new PdfSoundAction(sound);
action.volume = 1;
// Create a button and assign the action
let field: PdfButtonField = new PdfButtonField(
    page, 'PlaySound', { x: 20, y: 20, width: 120, height: 30 }
);
field.text = 'Play sound';
field.actions.mouseUp = action;
document.form.add(field);
// Save and destroy the document
document.save('output.pdf');
document.destroy();

Properties

Get mix boolean

Gets whether the sound is mixed with other sounds.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the sound button
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the sound action
let action: PdfSoundAction = field.actions.mouseUp as PdfSoundAction;
// Get the sound mixing setting
let mix: boolean = action.mix;
// Save and destroy the document
document.save('output.pdf');
document.destroy();

Set mix void

Sets whether the sound is mixed with other sounds.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the sound button
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the sound action
let action: PdfSoundAction = field.actions.mouseUp as PdfSoundAction;
// Enable sound mixing
action.mix = true;
// Save and destroy the document
document.save('output.pdf');
document.destroy();
Parameter Type Description
value boolean true to mix the sound with other sounds; otherwise, false.

Get next PdfAction

Get the next action to be performed after the action represented by this instance.

Set next void

Set the next action to be performed after the action represented by this instance.

Parameter Type Description
value PdfAction The next action to be executed.

Get repeat boolean

Gets whether the sound is repeated.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the sound button
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the sound action
let action: PdfSoundAction = field.actions.mouseUp as PdfSoundAction;
// Get the sound repeat setting
let repeat: boolean = action.repeat;
// Save and destroy the document
document.save('output.pdf');
document.destroy();

Set repeat void

Sets whether the sound is repeated.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the sound button
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the sound action
let action: PdfSoundAction = field.actions.mouseUp as PdfSoundAction;
// Enable sound repetition
action.repeat = true;
// Save and destroy the document
document.save('output.pdf');
document.destroy();
Parameter Type Description
value boolean true to repeat the sound; otherwise, false.

Get sound PdfSound

Gets the sound resource associated with the action.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the sound button
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the sound action and sound resource
let action: PdfSoundAction = field.actions.mouseUp as PdfSoundAction;
let sound: PdfSound = action.sound;
// Save and destroy the document
document.save('output.pdf');
document.destroy();

Set sound void

Sets the sound resource associated with the action.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the sound button
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the sound action
let action: PdfSoundAction = field.actions.mouseUp as PdfSoundAction;
// Create and configure a sound resource
let sound: PdfSound = new PdfSound(updatedSoundData);
sound.bits = 16;
sound.channels = PdfSoundChannels.Stereo;
sound.encoding = PdfSoundEncoding.Signed;
sound.rate = 44100;
// Set the sound resource
action.sound = sound;
// Save and destroy the document
document.save('output.pdf');
document.destroy();
Parameter Type Description
value PdfSound The sound resource to associate with the action.

Get synchronous boolean

Gets whether the sound is played synchronously.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the sound button
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the sound action
let action: PdfSoundAction = field.actions.mouseUp as PdfSoundAction;
// Get the synchronous playback setting
let synchronous: boolean = action.synchronous;
// Save and destroy the document
document.save('output.pdf');
document.destroy();

Set synchronous void

Sets whether the sound is played synchronously.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the sound button
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the sound action
let action: PdfSoundAction = field.actions.mouseUp as PdfSoundAction;
// Enable synchronous playback
action.synchronous = true;
// Save and destroy the document
document.save('output.pdf');
document.destroy();
Parameter Type Description
value boolean true to play the sound synchronously; otherwise, false.

Get volume number

Gets the playback volume of the sound.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the sound button
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the sound action
let action: PdfSoundAction = field.actions.mouseUp as PdfSoundAction;
// Get the sound volume
let volume: number = action.volume;
// Save and destroy the document
document.save('output.pdf');
document.destroy();

Set volume void

Sets the playback volume of the sound.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the sound button
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the sound action
let action: PdfSoundAction = field.actions.mouseUp as PdfSoundAction;
// Set the sound volume
action.volume = 0.8;
// Save and destroy the document
document.save('output.pdf');
document.destroy();
Parameter Type Description
value number The playback volume from -1 to 1.