通过 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. 使用 Document 實例載入 PDF。
  2. 使用 Document.Info 屬性取得 DocumentInfo。
  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)