PDF-Formulare. Verwaltung über Python

Acroforms im PDF-Dokument mit Aspose.PDF für die Python via .NET Library verwalten

So verwalten Sie PDF-Formulare mit Aspose.PDF für die Python via .NET Library

Um PDF-Formulare (Acroforms) in eine PDF-Datei einzufügen, verwenden wir die Aspose.PDF for Python via .NET API, eine funktionsreiche, leistungsstarke und einfach zu bedienende 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.

Console

pip install aspose-pdf

So erstellen Sie PDF-Formulare 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. Greifen Sie über ihren Index auf die Seite zu.
  3. Rufen Sie die Methode Add der Form-Auflistung auf.
  4. Erstellen Sie das Formularfeld, das Sie hinzufügen möchten.
  5. Speichern Sie die PDF-Datei.

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)