Add Image Stamp to PDF using Python

Create Image Stamp programmaticaly using Aspose.PDF for Python for .NET Tool

How to add Image Stamps to PDF using Python for .NET

In order to work with image stamp into PDF file, use Aspose.PDF for Python via .NET, a powerful and easy-to-use API. Open PyPI, search for aspose-pdf, and install it. Alternatively, run the command:

Console

pip install aspose-pdf

Add Image Stamp to PDF Document Python


You need Aspose.PDF for Python via .NET to try the code in your environment.

  1. Load the PDF with an instance of Document.
  2. Open a PDF document using Document object.
  3. Create a Image Stamp and define its properties.
  4. Add the Stamp to Page using AddStamp method

Add Image Stamp to 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 )