Lavora con timbri in formato PDF tramite Python

Stampaggio con Aspose.PDF utilizzando le API Python

Come aggiungere timbri al PDF utilizzando la libreria Python via .NET

Per lavorare con un timbro di testo in un file PDF, useremo l’API Aspose.PDF for .NET, un’API di manipolazione di documenti ricca di funzionalità, potente e facile da usare per la piattaforma python-net. Apri il gestore di pacchetti NuGet, cerca Aspose.pdf e installa. È inoltre possibile utilizzare il seguente comando dalla console di Package Manager.

Python Package Manager Console

pip install aspose-pdf

Aggiungi timbro al documento PDF Python


È necessario Aspose.PDF for .NET per provare il codice nel proprio ambiente.

  1. Carica il PDF con un’istanza di Document.
  2. Ottieni DocumentInfo utilizzando la proprietà Document.Info.
  3. Accedere e visualizzare diverse proprietà di Document.Info.

Aggiungi timbro al PDF - Python

    # Open document
    pdfDocument = new Document(dataDir+ "AddTextStamp.pdf")
    # Create text stamp
    textStamp = TextStamp("Sample Stamp")
    # Set whether stamp is background
    textStamp.Background = True
    # Set origin
    textStamp.XIndent = 100
    textStamp.YIndent = 100
    # Rotate stamp
    textStamp.Rotate = Rotation.on90
    # Set text properties
    textStamp.TextState.Font = FontRepository.FindFont("Arial")
    textStamp.TextState.FontSize = 14
    textStamp.TextState.FontStyle = FontStyles.Bold
    textStamp.TextState.FontStyle = FontStyles.Italic
    textStamp.TextState.ForegroundColor = System.Drawing.Color.Aqua
    # Add stamp to particular page
    pdfDocument.Pages[1].AddStamp(textStamp)

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