PDF-Formulare. Über Python verwalten

Verwalten Sie Acroforms in PDF-Dokumenten mit der Bibliothek „Aspose.PDF for Python via .NET“

So verwalten Sie PDF-Formulare mithilfe der Bibliothek Python via .NET

Um PDF-Formulare (Acroforms) in eine PDF-Datei einzufügen, verwenden wir die Aspose.PDF for Python via .NET API, eine funktionsreiche, leistungsstarke und benutzerfreundliche API zur Dokumentbearbeitung für Python-Apps. Sie können die neueste Version direkt vom PyPi-Paketmanager 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. Laden Sie PDF in einer Instanz der Document-Klasse.
  2. Zugriff auf die Seite über ihren Index.
  3. Rufen Sie die Add-Methode 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)