Add List Item

Contents
[ ]

List box fields in PDFs allow users to select one or multiple options from a predefined set. Using Aspose.PDF for Python, developers can programmatically add new items to these fields. The FormEditor class provides the ‘add_list_item’ method to append items to an existing list box field.

  1. Open an existing PDF form.
  2. Create a FormEditor object.
  3. Bind the PDF to the FormEditor.
  4. Add items to the list box field “Country”.
  5. Save the updated document.
from io import FileIO
import sys
from os import path
import aspose.pdf as ap
import aspose.pdf.facades as pdf_facades

sys.path.append(path.join(path.dirname(__file__), ".."))

from config import set_license, initialize_data_dir


def add_list_item(infile, outfile):
    # Create FormEditor object
    form_editor = pdf_facades.FormEditor()
    # Bind document to FormEditor
    form_editor.bind_pdf(infile)
    # Add list item to list box field
    form_editor.add_list_item("Country", ["New Zealand", "New Zealand"])
    # Save updated document
    form_editor.save(outfile)