サウンド注釈を追加

Contents
[ ]

PDF のサウンド注釈を使用すると、音声メモ、音楽、効果音などのオーディオコンテンツを文書に追加できます。を使用する PDF コンテンツエディターページ上にクリック可能な小さな四角形を定義して、アクティブにすると指定したオーディオファイルを再生できます。

  1. PDF コンテンツエディターのインスタンスを作成します。
  2. 入力 PDF ドキュメントをバインドします。
  3. サウンドアノテーションの長方形を定義します。
  4. オーディオファイル、注釈名、ページ番号、およびサンプリングレートを指定します。
  5. 更新した 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)