列出印章

Contents
[ ]

在处理带有注释的 PDF 时,您可能需要在修改或删除之前检查现有的橡胶印章。‘get_stamps()’ 方法允许您检索特定页面上放置的所有印章。随后您可以遍历结果并以编程方式处理它们。

  1. 创建一个 PdfContentEditor 实例。
  2. 绑定输入的 PDF 文档。
  3. 检索第 1 页的所有印章。
  4. 遍历印章集合。
  5. 打印每个印章。
  6. 如果不存在印章,显示一条消息。
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 list_stamps(infile):
    # Create PdfContentEditor object
    content_editor = pdf_facades.PdfContentEditor()
    # Bind document to PdfContentEditor
    content_editor.bind_pdf(infile)
    # List all stamps on page 1
    stamps = content_editor.get_stamps(1)

    count = 0
    for stamp in stamps:
        count += 1
        print(f"Stamp {count}: {stamp}")

    if count == 0:
        print("No stamps found")