Pindahkan Stempel Berdasarkan Indeks

Contents
[ ]

Dalam penyuntingan PDF, mungkin perlu menyesuaikan posisi stempel karet yang ada. Cuplikan kode ini menunjukkan caranya:

  • Tambahkan beberapa stempel pada halaman yang sama
  • Siapkan mereka untuk dipindahkan posisinya menggunakan indeks mereka
  • Opsional, pindahkan stempel dengan menentukan halaman, indeks, dan koordinat baru

Metode ‘move_stamp(page_number, stamp_index, new_x, new_y)’ dapat memposisikan ulang stempel dengan tepat.

  1. Buat sebuah PdfContentEditor objek.
  2. Hubungkan PDF ke editor.
  3. Tambahkan beberapa stempel karet ke halaman.
  4. Simpan dokumen sebelum melakukan operasi pemindahan.
  5. Pindahkan stempel tertentu berdasarkan indeksnya.
  6. Simpan PDF yang diperbarui.
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)