Create AcroForm - Create Fillable PDF in Python

Create form from scratch

Add Form Field in a PDF Document

The Document class provides a collection named Form which helps you manage form fields in a PDF document.

To add a form field:

  1. Create the form field you want to add.
  2. Call the Form collection’s add method.

Adding TextBoxField

Below example shows how to add a TextBoxField.


    import aspose.pdf as ap

    # Open document
    pdfDocument = ap.Document(input_file)

    # Create a field
    textBoxField = ap.forms.TextBoxField(pdfDocument.pages[1], ap.Rectangle(100, 200, 300, 300, True))
    textBoxField.partial_name = "textbox1"
    textBoxField.value = "Text Box"

    border = ap.annotations.Border(textBoxField)
    border.width = 5
    border.dash = ap.annotations.Dash(1, 1)
    textBoxField.border = border

    textBoxField.color = ap.Color.green

    # Add field to the document
    pdfDocument.form.add(textBoxField, 1)

    # Save modified PDF
    pdfDocument.save(output_pdf)