Stamps in PDF using Python

Stamping PDF documents with Python via .NET. Use Aspose.PDF to modify PDF documents programmatically

How to add Stamps to PDF using Python via .NET Library

In order to work with text 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 Stamp to PDF Document Python


You need [Aspose.PDF for Python via .NET]https://releases.aspose.com/pdf/net) to try the code in your environment.

  1. Load the PDF with an instance of Document.
  2. Get DocumentInfo using Document.Info property.
  3. Access & display different Document.Info properties.

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