添加声音注释
Contents
[
Hide
]
PDF 中的声音注释使您能够向文档添加音频内容,例如语音备注、音乐或音效。使用 PdfContentEditor, 您可以在页面上定义一个小的可点击矩形,激活后播放指定的音频文件。
- 创建一个 PdfContentEditor 实例。
- 绑定输入的 PDF 文档。
- 为声音注释定义一个矩形。
- 指定音频文件、注释名称、页码和采样率。
- 保存更新后的 PDF 文档。
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)