Create ComboBox Field
Contents
[
Hide
]
PDF forms are widely used for collecting structured information in digital documents such as applications, surveys, and registration forms. A ComboBox field provides a convenient way for users to choose from a list of predefined values while keeping the form compact and organized.
The FormEditor class allows you to create and manage different types of fields, including text boxes, checkboxes, radio buttons, and drop-down lists.
- Load an existing PDF document.
- Add a ComboBox field with ‘add_field()’ method and ‘FieldType.COMBO_BOX’ parameter.
- Use the ‘add_list_item()’ method to insert selectable options into the drop-down list.
- Save the updated PDF document.
import sys
from os import path
import aspose.pdf.facades as pdf_facades
sys.path.append(path.join(path.dirname(__file__), ".."))
from config import set_license, initialize_data_dir
def create_combobox_field(infile, outfile):
"""Create ComboBox field in PDF document."""
pdf_form_editor = pdf_facades.FormEditor()
pdf_form_editor.bind_pdf(infile)
# Add ComboBox field to PDF form
pdf_form_editor.add_field(
pdf_facades.FieldType.COMBO_BOX, "combobox1", "Australia", 1, 230, 498, 350, 514
)
pdf_form_editor.add_list_item("combobox1", ["Australia", "Australia"])
pdf_form_editor.add_list_item("combobox1", ["New Zealand", "New Zealand"])
# Save updated PDF document with form fields
pdf_form_editor.save(outfile)