使用外观文件创建橡皮图章
Contents
[
Hide
]
橡皮图章注释不仅可以使用文本进行自定义,还可以通过使用图像文件作为其外观进行定制。这种方法对于在 PDF 页面上添加公司徽标、签名图章或任何视觉指示器非常有用。
- 创建一个 PdfContentEditor 实例。
- 绑定输入的 PDF 文档。
- 为图章定义一个矩形。
- 使用自定义图像文件来定义橡皮图章的外观。
- 设置图章的文本和颜色。
- 保存更新后的 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 create_rubber_stamp_with_appearance_file(infile, image_file, outfile):
# Create PdfContentEditor object
content_editor = pdf_facades.PdfContentEditor()
# Bind document to PdfContentEditor
content_editor.bind_pdf(infile)
# Create rubber stamp using appearance_file overload (image path)
content_editor.create_rubber_stamp(
1,
apd.Rectangle(100, 400, 200, 60),
"Stamp with custom appearance",
apd.Color.dark_green,
image_file,
)
# Save updated document
content_editor.save(outfile)