Pdf Component - PdfSound
18 Nov 20268 minutes to read
Represents an embedded sound resource in a PDF document.
// 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);
// 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 bits number
Gets the number of bits per audio sample.
// 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 bits per sample
let action: PdfSoundAction = field.actions.mouseUp as PdfSoundAction;
let bits: number = action.sound.bits;
// Save and destroy the document
document.save('output.pdf');
document.destroy();Set bits void
Sets the number of bits per audio sample.
// 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 number of bits per sample
action.sound.bits = 16;
// Save and destroy the document
document.save('output.pdf');
document.destroy();| Parameter | Type | Description |
|---|---|---|
| value | number |
The number of bits per audio sample. |
Get channels PdfSoundChannels
Gets the channel layout of the sound resource.
// 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 channel layout
let action: PdfSoundAction = field.actions.mouseUp as PdfSoundAction;
let channels: PdfSoundChannels = action.sound.channels;
// Save and destroy the document
document.save('output.pdf');
document.destroy();Set channels void
Sets the channel layout of the sound resource.
// 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 channel layout
action.sound.channels = PdfSoundChannels.Stereo;
// Save and destroy the document
document.save('output.pdf');
document.destroy();| Parameter | Type | Description |
|---|---|---|
| value | PdfSoundChannels |
The channel layout of the sound resource. |
Get data Uint8Array
Gets the embedded audio data.
// 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 audio data
let action: PdfSoundAction = field.actions.mouseUp as PdfSoundAction;
let soundData: Uint8Array = action.sound.data;
// Save and destroy the document
document.save('output.pdf');
document.destroy();Set data void
Sets the embedded audio data.
// 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 embedded audio data
action.sound.data = updatedSoundData;
// Save and destroy the document
document.save('output.pdf');
document.destroy();| Parameter | Type | Description |
|---|---|---|
| value | Uint8Array |
The audio data to embed. |
Get encoding PdfSoundEncoding
Gets the audio encoding of the sound resource.
// 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 audio encoding
let action: PdfSoundAction = field.actions.mouseUp as PdfSoundAction;
let encoding: PdfSoundEncoding = action.sound.encoding;
// Save and destroy the document
document.save('output.pdf');
document.destroy();Set encoding void
Sets the audio encoding of the sound resource.
// 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 audio encoding
action.sound.encoding = PdfSoundEncoding.Signed;
// Save and destroy the document
document.save('output.pdf');
document.destroy();| Parameter | Type | Description |
|---|---|---|
| value | PdfSoundEncoding |
The audio encoding of the sound resource. |
Get rate number
Gets the sampling rate of the sound resource.
// 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 sampling rate
let action: PdfSoundAction = field.actions.mouseUp as PdfSoundAction;
let rate: number = action.sound.rate;
// Save and destroy the document
document.save('output.pdf');
document.destroy();Set rate void
Sets the sampling rate of the sound resource.
// 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 sampling rate
action.sound.rate = 44100;
// Save and destroy the document
document.save('output.pdf');
document.destroy();| Parameter | Type | Description |
|---|---|---|
| value | number |
The number of audio samples per second. |