Fill List Box

Contents
[ ]

List box and multi-select fields allow users to choose one or multiple values from a predefined set of options. In this example, the Form facade from aspose.pdf.facades is used to access the PDF form and assign a selected value to the favorite_colors field. Once the desired option is selected, the updated document is saved.

  1. Initialize ‘pdf_facades.Form()’ to manage and update form fields.
  2. Call ‘bind_pdf()’ to attach the source PDF containing list box or multi-select fields.
  3. Use ‘fill_field()’ to select a value from the available options.
  4. 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


# Fill List Box / Multi-Select Fields
def fill_list_box_fields(infile, outfile):
    """Fill list box and multi-select fields in PDF form."""
    # Create Form object
    pdf_form = pdf_facades.Form()

    # Bind PDF document
    pdf_form.bind_pdf(infile)

    # Fill list box / multi-select fields by name
    pdf_form.fill_field("favorite_colors", "Red")

    # Save updated PDF
    pdf_form.save(outfile)