Pindahkan Stempel Berdasarkan Indeks
Contents
[
Hide
]
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.
- Buat sebuah PdfContentEditor objek.
- Hubungkan PDF ke editor.
- Tambahkan beberapa stempel karet ke halaman.
- Simpan dokumen sebelum melakukan operasi pemindahan.
- Pindahkan stempel tertentu berdasarkan indeksnya.
- 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)