Add Image Stamp to PDF via Python

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

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

In order to work with image stamp into PDF file, we’ll use Aspose.PDF for .NET API which is a feature-rich, powerful and easy to use document manipulation API for python-net platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Python Package Manager Console

pip install aspose-pdf

Add Image Stamp to PDF Document Python


You need Aspose.PDF for Python 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

    # Open document
    pdfDocument = Document(dataDir+ "AddImageStamp.pdf")

    # Create image stamp
    imageStamp = ImageStamp(dataDir + "aspose-logo.jpg")
    imageStamp.Background = true
    imageStamp.XIndent = 100
    imageStamp.YIndent = 100
    imageStamp.Height = 300
    imageStamp.Width = 300
    imageStamp.Rotate = Rotation.on270
    imageStamp.Opacity = 0.5

    # Add stamp to particular page
    pdfDocument.Pages[1].AddStamp(imageStamp)

    dataDir = dataDir + "AddImageStamp_out.pdf"
    # Save output document
    pdfDocument.Save(dataDir)