Hapus Stempel Secara Global
Contents
[
Hide
]
Saat bekerja dengan banyak halaman, Anda mungkin perlu menghapus stempel tertentu di seluruh dokumen. Metode ‘delete_stamp_by_id()’ dan ‘delete_stamp_by_ids()’ memungkinkan Anda menghapus stempel secara global berdasarkan identifier mereka, menghilangkan kebutuhan untuk mengulangi proses melalui setiap halaman secara manual.
- Buat sebuah PdfContentEditor instance.
- Hubungkan dokumen PDF input.
- Tambahkan stempel karet ke beberapa halaman.
- Hapus stempel secara global menggunakan ID mereka.
- Simpan dokumen 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 delete_stamps_globally(infile, outfile):
# Create PdfContentEditor object
content_editor = pdf_facades.PdfContentEditor()
# Bind document to PdfContentEditor
content_editor.bind_pdf(infile)
# Add stamps across multiple pages so global deletion is meaningful
for page in range(1, 5):
content_editor.create_rubber_stamp(
page,
apd.Rectangle(120, 500, 180, 60),
"Draft",
"Stamp for global deletion",
apd.Color.gray,
)
# delete_stamp_by_id without page number removes stamp ID from all pages
content_editor.delete_stamp_by_id(1)
# delete_stamp_by_ids without page number removes a list of IDs from all pages
content_editor.delete_stamp_by_ids([2, 3])
# Save updated document
content_editor.save(outfile)