通过 Python 以 PDF 格式制作邮票

使用 Python via .NET 加盖印章 PDF 文档。使用 Aspose.PDF 以编程方式修改 PDF 文档

如何使用 Python via .NET 库将图章添加到 PDF

为了在 PDF 文件中使用文本戳记,请使用 Aspose.PDF for Python via .NET,这是一个功能强大且易于使用的 API。打开 PyPI,搜索 aspose-pdf 并安装。或者,运行以下命令:

Console

pip install aspose-pdf

将图章添加到 PDF 文档 Python


您需要[通过 .NET 的 Python Aspose.PDF]https://releases.aspose.com/pdf/net) 在您的环境中尝试代码。

  1. 使用 “文档” 实例加载 PDF。
  2. 使用 Document.Info 属性获取文档信息。
  3. 访问并显示不同的 Document.Info 属性。

向 PDF 添加图章-Python

import aspose.pdf as apdf

from os import path

path_infile = path.join(self.data_dir, infile)
path_outfile = path.join(self.data_dir, outfile)

document = apdf.Document(path_infile)

# Create text stamp
textStamp = apdf.TextStamp("Sample Stamp")
# Set whether stamp is background
textStamp.background = True
# Set origin
textStamp.x_indent = 100
textStamp.y_indent = 100
# Rotate stamp
textStamp.rotate = apdf.Rotation.ON90
# Set text properties
textStamp.text_state.font = apdf.text.FontRepository.find_font("Arial")
textStamp.text_state.font_size = 14
textStamp.text_state.font_style = apdf.text.FontStyles(apdf.text.FontStyles.BOLD | apdf.text.FontStyles.ITALIC)
textStamp.text_state.foreground_color = apdf.Color.aqua
# Add stamp to particular page
document.pages[1].add_stamp(textStamp)

# Save output document
document.save(path_outfile)