通过 Python 向 PDF 添加图像图章

使用 Aspose.PDF 为 Python for .NET 库以编程方式创建图像图章

如何使用 Python for .NET 庫將圖像圖章添加到 PDF

為了將圖像圖章新增至 PDF 檔案中,請使用 Aspose.PDF for Python via .NET,這是一個功能強大且易於使用的 API。開啟 PyPI,搜尋 aspose-pdf 並安裝。或者,執行以下命令:

Console

pip install aspose-pdf

將影像圖章加入到 PDF 文件 Python


你需要 通过.NET for Python 的 Aspose.PDF 才能在你的环境中试用代码。

  1. 使用 Document 實例載入 PDF。
  2. 使用 Document 物件開啟 PDF 文件。
  3. 建立影像圖章並定義其屬性。
  4. 使用 AddStamp 方法將圖章新增至頁面

向 PDF 添加图像图章-Python

import aspose.pdf as apdf

from os import path

path_infile = path.join(self.data_dir, infile)
path_input_image = path.join(self.data_dir, "image.pdf")
path_outfile = path.join(self.data_dir, outfile)

document = apdf.Document(path_infile)

image_stamp = apdf.ImageStamp(path_input_image)
image_stamp.background = True
image_stamp.x_indent = 100
image_stamp.y_indent = 100
image_stamp.height = 300
image_stamp.width = 300
image_stamp.rotate = apdf.Rotation.ON270
image_stamp.opacity = 0.5

document.pages[1].add_stamp(image_stamp)
document.save(path_outfile )