Add Text Stamp to PDF via Python

Create text stamp programmaticaly using Aspose.PDF for Python for .NET Library

How to add Text Stamps to PDF Using Python for .NET Library

In order to work with text 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 Text 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 Text Stamp and define its properties.
  4. Add the Text Stamp to Page using AddStamp method

Add Text Stamp to PDF with Python

import aspose.pdf as ap
# Open document

pdfDocument = ap.Document()
pdfDocument.pages.add()
# Create text stamp
textStamp = ap.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 = ap.Rotation.ON90
# Set text properties
textStamp.text_state.font = ap.text.FontRepository.find_font("Arial")
textStamp.text_state.font_size = 14
textStamp.text_state.font_style = ap.text.FontStyles( 
    ap.text.FontStyles.BOLD | ap.text.FontStyles.ITALIC )
textStamp.text_state.foreground_color = ap.Color.aqua
# Add stamp to particular page
pdfDocument.pages[1].add_stamp(textStamp)

# Save output document
pdfDocument.save("AddTextStamp_out.pdf")