全局删除印章
Contents
[
Hide
]
在处理多页文档时,您可能需要在整个文档中删除某些印章。‘delete_stamp_by_id()’ 和 ‘delete_stamp_by_ids()’ 方法允许您通过标识符全局删除印章,无需手动遍历每一页。
- 创建一个 PdfContentEditor 实例。
- 绑定输入的 PDF 文档。
- 在多个页面上添加橡胶印章。
- 使用其 ID 全局删除印章。
- 保存更新后的 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 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)