Agregue un sello de texto a un PDF a través de Python

Cree un sello de texto mediante programación utilizando Aspose.PDF for la biblioteca Python for .NET

Cómo añadir sellos de texto a un PDF con la biblioteca Python for .NET

Para trabajar con el sello de texto en un archivo PDF, utilice Aspose.PDF for Python via .NET, una API potente y fácil de usar. Abra PyPI, busque aspose-pdf e instálelo. También puede ejecutar el comando:

Console

pip install aspose-pdf

Agregar sello de texto al documento PDF Python


Necesita Aspose.PDF para Python a través de.NET para probar el código en su entorno.

  1. Cargue el PDF con una instancia de Document.
  2. Abra un documento PDF con el objeto Document.
  3. Cree un sello de texto y defina sus propiedades.
  4. Agregar el sello de texto a la página mediante el método AddStamp

Añadir sello de texto a PDF con 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)
document.pages.add()
# 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)