Add Sound Annotation
Contents
[
Hide
]
Sound annotations in PDFs enable you to add audio content such as voice notes, music, or sound effects to your documents. Using PdfContentEditor, you can define a small clickable rectangle on a page that plays a specified audio file when activated.
- Create a PdfContentEditor instance.
- Bind the input PDF document.
- Define a rectangle for the sound annotation.
- Specifie the audio file, annotation name, page number, and sampling rate.
- Save the updated PDF document.
import aspose.pdf.facades as pdf_facades
import aspose.pydrawing as apd
import sys
from os import path
sys.path.append(path.join(path.dirname(__file__), ".."))
from config import set_license, initialize_data_dir
def add_sound_annotation(infile, sound_file, outfile):
# Create PdfContentEditor object
content_editor = pdf_facades.PdfContentEditor()
# Bind document to PdfContentEditor
content_editor.bind_pdf(infile)
# Add sound annotation to page 1
content_editor.create_sound(
apd.Rectangle(80, 450, 30, 30), sound_file, "Speaker", 1, "8000"
)
# Save updated document
content_editor.save(outfile)