添加橡胶印章

Contents
[ ]

橡胶印章注释通常用于 PDF 中,以指示批准、审阅状态或其他备注。使用 PdfContentEditor,您可以为印章定义矩形,设置其文本和注释,选择颜色,并将其应用于文档的多个页面。

  1. 创建一个 PdfContentEditor 实例。
  2. 绑定输入的 PDF 文档。
  3. 循环遍历第 1–4 页。
  4. 添加带有自定义文本、注释和颜色的橡胶印章注释。
  5. 保存更新后的 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 add_rubber_stamp(infile, outfile):
    # Create PdfContentEditor object
    content_editor = pdf_facades.PdfContentEditor()
    # Bind document to PdfContentEditor
    content_editor.bind_pdf(infile)

    for i in range(1, 5):
        content_editor.create_rubber_stamp(
            i,
            apd.Rectangle(120, 450, 180, 60),
            "Approved",
            "Approved by reviewer",
            apd.Color.green,
        )
    # Save updated document
    content_editor.save(outfile)