スタンプをインデックスで移動

Contents
[ ]

PDF編集では、既存のラバースタンプの位置を調整する必要がある場合があります。このコードスニペットは、以下の方法を示しています。

  • 同じページに複数のスタンプを追加
  • インデックスを使って再配置の準備をする
  • 必要に応じて、ページ、インデックス、および新しい座標を指定してスタンプを移動します

‘move_stamp (ページ番号、スタンプインデックス、new_x、new_y) ‘メソッドを使うと、スタンプを正確に再配置できます。

  1. を作成 PDF コンテンツエディター 対象。
  2. PDF をエディターにバインドします。
  3. ページに複数のラバースタンプを追加します。
  4. 移動操作を実行する前に文書を保存してください。
  5. 特定のスタンプをインデックス単位で移動します。
  6. 更新した PDF を保存します。
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 move_stamp_by_index(infile, outfile):
    # Create PdfContentEditor object
    content_editor = pdf_facades.PdfContentEditor()
    # Bind document to PdfContentEditor
    content_editor.bind_pdf(infile)

    content_editor.create_rubber_stamp(
        2,
        apd.Rectangle(200, 380, 180, 60),
        "Draft",
        "Draft stamp for ID-based operations",
        apd.Color.orange,
    )

    content_editor.create_rubber_stamp(
        2,
        apd.Rectangle(200, 480, 180, 60),
        "Draft",
        "Draft stamp for ID-based operations",
        apd.Color.orange,
    )
    content_editor.save(outfile)

    # Move first stamp on page 1 by index
    # content_editor.move_stamp(1, 1, 10, 10)
    # Save updated document
    content_editor.save(outfile)