Delete List Item

Contents
[ ]

List box fields in PDFs allow users to select one or multiple predefined options. Using Aspose.PDF for Python, developers can programmatically remove items from these fields.

This article explains how to delete the ‘UK’ item from a list box field named ‘Country’, ensuring the field only contains the desired options.

The FormEditor class provides the ‘del_list_item’ method to remove a specific item from a list box field.

  1. Open an existing PDF form.
  2. Create a FormEditor object.
  3. Bind the PDF document to the FormEditor.
  4. Delete the “UK” item from the “Country” list box field.
  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 del_list_item(infile, outfile):
    # Create FormEditor object
    form_editor = pdf_facades.FormEditor()
    # Bind document to FormEditor
    form_editor.bind_pdf(infile)
    # Delete list item from list box field
    form_editor.del_list_item("Country", "UK")
    # Save updated document
    form_editor.save(outfile)