Timbres au format PDF via Python

Tamponner les documents PDF avec Python via .NET. Utilisez Aspose.PDF pour modifier les documents PDF par programmation

Comment ajouter des tampons au PDF à l'aide de la bibliothèque Python via .NET

Pour intégrer du texte dans un fichier PDF, utilisez Aspose.PDF for Python via .NET, une API puissante et intuitive. Ouvrez PyPI, recherchez « aspose-pdf » et installez-le. Vous pouvez également exécuter la commande suivante :

Console

pip install aspose-pdf

Ajouter un cachet au document PDF Python


Vous avez besoin de [Aspose.PDF pour Python via .NET] https://releases.aspose.com/pdf/net) pour essayer le code dans votre environnement.

  1. Chargez le PDF avec une instance de Document.
  2. Obtenez DocumentInfo à l’aide de la propriété Document.Info.
  3. Accédez et affichez différentes propriétés de Document.Info.

Ajoutez Stamp au 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)