Erstellen Sie PDF-Formulare über Python

Programmgesteuertes Erstellen von Akroformen in PDF mit Aspose.PDF for die Python for .NET Library

So erstellen Sie PDF-Formulare mit Python

Um PDF-Formulare (Acroforms) in einer PDF-Datei zu erstellen, verwenden wir die Aspose.PDF for .NET API, eine funktionsreiche, leistungsstarke und benutzerfreundliche API zur Dokumentenmanipulation für die C#-Plattform. Öffnen Sie den NuGet Paketmanager, suchen Sie nach Aspose.pdf und installieren Sie ihn. Sie können auch den folgenden Befehl von der Package Manager Console aus verwenden.

So erstellen Sie AcroForm in PDF mit Python


Sie benötigen Aspose.PDF for .NET, um den Code in Ihrer Umgebung auszuprobieren.

  1. Laden Sie PDF in einer Instanz der Document-Klasse.
  2. Erstellen Sie ein Feld.
  3. Erstellen Sie Dekorationen (wie Border).
  4. Feld zum Dokument hinzufügen und geänderte PDF speichern

Erstellen Sie PDF-Formulare in PDF - Python

Dieser Beispielcode zeigt, wie Sie PDF-Formulare in PDF mit Python erstellen

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)