Erstellen Sie PDF-Formulare über Python

Programmgesteuertes Erstellen von Akroformen in PDF mit Aspose.PDF für 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 Python via .NET API, eine funktionsreiche, leistungsstarke und benutzerfreundliche API zur Dokumentenbearbeitung für die Python-App. Sie können die neueste Version direkt vom Paketmanager PyPI herunterladen, nach aspose-pdf suchen und installieren. Sie können auch den folgenden Befehl von der Konsole oder dem Terminal aus verwenden.

So erstellen Sie AcroForm in PDF mit Python


Sie benötigen Aspose.PDF für Python via .NET, um den Code in Ihrer Umgebung auszuprobieren.

  1. Lädt PDF in eine Instanz der Document-Klasse.
  2. Erstellen Sie ein Feld.
  3. Erstellen Sie Dekorationen (wie Border).
  4. Fügen Sie dem Dokument ein Feld hinzu und speichern Sie das geänderte PDF

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)