Create RadioButton Field

Contents
[ ]

Interactive PDF forms enable users to provide structured input directly within a document. A radio button field is useful when users must choose only one option from multiple choices, such as selecting a country, gender, or preference.

The FormEditor class provides methods to create different types of fields, including text boxes, checkboxes, combo boxes, list boxes, and radio buttons.

  1. Load an existing PDF document.
  2. Define a list of radio button options.
  3. Add a radio button field to a specific page.
  4. Set a default selected value.
  5. Save the modified 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_radiobutton_field(infile, outfile):
    """Create RadioButton field in PDF document."""
    pdf_form_editor = pdf_facades.FormEditor()
    pdf_form_editor.bind_pdf(infile)

    # Add RadioButton field to PDF form
    pdf_form_editor.items = ["Australia", "New Zealand", "Malaysia"]
    pdf_form_editor.add_field(
        pdf_facades.FieldType.RADIO, "radiobutton1", "Malaysia", 1, 240, 498, 256, 514
    )

    # Save updated PDF document with form fields
    pdf_form_editor.save(outfile)