Add List Item
Contents
[
Hide
]
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.
- Open an existing PDF form.
- Create a FormEditor object.
- Bind the PDF to the FormEditor.
- Add items to the list box field “Country”.
- 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)