PDF 内の画像の置換

Contents
[ ]

PDF には、ロゴ、図、写真など、更新や置換が必要な画像が含まれていることがよくあります。と PDF コンテンツエディターページ番号、画像インデックス、および新しい画像ファイルパスを指定することで、特定のページの特定の画像を置き換えることができます。

  1. PDF コンテンツエディターのインスタンスを作成します。
  2. 入力 PDF ドキュメントをバインドします。
  3. 特定のページの特定の画像を置き換えます。
  4. 更新した PDF ドキュメントを保存します。
import aspose.pdf.facades as pdf_facades
import sys
from os import path

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

from config import set_license, initialize_data_dir


def replace_image(infile, image_file, outfile):
    # Create PdfContentEditor object
    content_editor = pdf_facades.PdfContentEditor()
    # Bind document to PdfContentEditor
    content_editor.bind_pdf(infile)
    # Replace image on page 1
    content_editor.replace_image(1, 1, image_file)
    # Save updated document
    content_editor.save(outfile)