Crea moduli PDF tramite Python

Crea acroform in PDF a livello di codice utilizzando Aspose.PDF per la libreria Python for .NET

Come creare moduli PDF usando Python

Per creare moduli PDF (Acroforms) in un file PDF, utilizzeremo l’API Aspose.PDF per Python via .NET, un’API di manipolazione dei documenti ricca di funzionalità, potente e facile da usare per l’app Python. 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.

Come creare AcroForm in PDF usando 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. Crea un campo.
  3. Crea decorazioni (come Border).
  4. Aggiungi un campo al documento e salva il PDF modificato

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)