Moduli PDF. Gestisci tramite Python

Gestisci gli Acroform nel documento PDF utilizzando la libreria Aspose.PDF for Python via .NET

Come gestire i moduli PDF utilizzando Aspose.PDF per la libreria Python via .NET

Per aggiungere moduli PDF (Acroforms) in un file PDF, utilizzeremo l’API Aspose.PDF per Python via .NET, che è un’API di manipolazione dei documenti per l’app Python ricca di funzionalità, potente e facile da usare. Puoi scaricare l’ultima versione direttamente dal gestore di pacchetti PyPI, cercare aspose-pdf e installarlo. Puoi anche usare il seguente comando dalla console o dal terminale.

Console

pip install aspose-pdf

Come creare moduli PDF utilizzando Python

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

  1. Carica il PDF in un’istanza della classe Document.
  2. Accedi alla Pagina tramite il suo indice.
  3. Chiamate il metodo Add dell’insieme Form.
  4. Crea il campo del modulo che desideri aggiungere.
  5. Salva il file PDF.

Crea moduli PDF in PDF - Python

Questo codice di esempio mostra come creare moduli PDF in PDF utilizzando 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 a new text box field
rectange = apdf.Rectangle(100, 100, 200, 120, True)
textBoxField = apdf.forms.TextBoxField(document.pages[1], rectange)
textBoxField.partial_name = "textbox1"
textBoxField.value = "Text Box"

# Customize the border of the text box field
border = apdf.annotations.Border(textBoxField)
border.width = 3
border.dash = apdf.annotations.Dash(1, 1)
textBoxField.border = border

# Set the color of the text box field
textBoxField.color = apdf.Color.dark_green

# Add the text box field to the form
document.form.add(textBoxField, 1)

# Save the modified PDF document
document.save(path_outfile)