PDF Forms. Manage via Python

Manage Acroforms in PDF document using Aspose.PDF for Python via .NET Library

Most popular actions with Acroforms in Python

How to Manage PDF Forms Using Python via .NET Library

In order to add PDF Forms (Acroforms) in a PDF file, we’ll use Aspose.PDF for .NET API, which is feature-rich, powerful, and easy-to-use document manipulation API for python-net platform. You can download its latest version directly from NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Python Package Manager Console

pip install aspose-pdf

How to Create PDF Forms using Python


You need Aspose.PDF for Python to try the code in your environment.

  1. Load PDF in an instance of Document class.
  2. Access the Page via its index.
  3. Call the Form collection’s Add method.
  4. Create the form field you want to add.
  5. Save the PDF file.

Create PDF Forms in PDF - Python

This sample code shows how to Create PDF Forms in PDF using Python

    def add_text_box_field(self, infile, outfile):

            path_infile = self.dataDir + infile
            path_outfile = self.dataDir + outfile

            # Open document
            pdfDocument = Document(path_infile);

            # Create a field
            textBoxField = TextBoxField(pdfDocument.Pages[1], Rectangle(100, 200, 300, 300));
            textBoxField.PartialName = "textbox1";
            textBoxField.Value = "Text Box";

            border = Border(textBoxField);
            border.Width = 5;
            border.Dash = Dash(1, 1);
            textBoxField.Border = border;

            textBoxField.Color = Color.FromRgb(Color.Green);

            # Add field to the document
            pdfDocument.Form.Add(textBoxField, 1);

            # Save modified PDF
            pdfDocument.Save(path_outfile);