添付ファイル注記を追加

Contents
[ ]

ファイル添付注釈を使用すると、外部ファイルをインタラクティブなアイコンとして PDF ページに埋め込むことができます。ファイルパスオーバーロードを使用すると、ストリームを手動で開かなくてもディスクから直接ファイルを添付できます。この方法では、注釈アイコンをカスタマイズしたり、ユーザーに説明を提供したりすることもできます。

  1. 作成 PDF コンテンツエディター 対象。
  2. 入力 PDF をバインドします。
  3. 注釈長方形を定義します。
  4. 添付ファイルの注釈を追加します。
  5. 更新したドキュメントを保存します。
import aspose.pdf.facades as pdf_facades
import aspose.pydrawing as apd
from io import BytesIO
import sys
from os import path

sys.path.append(path.join(path.dirname(__file__), ".."))

from config import set_license, initialize_data_dir


def add_file_attachment_annotation(infile, attachment_file, outfile):
    # Create PdfContentEditor object
    content_editor = pdf_facades.PdfContentEditor()
    # Bind document to PdfContentEditor
    content_editor.bind_pdf(infile)
    # Create file attachment annotation on page 1
    content_editor.create_file_attachment(
        apd.Rectangle(100, 520, 20, 20),
        "Attachment annotation contents",
        attachment_file,
        1,
        "PushPin",
    )
    # Save updated document
    content_editor.save(outfile)