Fill Radio Button Fields
Contents
[
Hide
]
Radio buttons allow users to select a single option from a predefined group, such as gender or preference fields. In this example, the Form facade from the aspose.pdf.facades module is used to bind the source PDF and assign a selected option by its index value. Once the desired option is chosen, the modified document is saved.
- Initialize pdf_facades.Form() to manage PDF form fields.
- Call ‘bind_pdf()’ to attach the PDF containing radio button fields.
- Use ‘fill_field()’ to select the first option (index 0).
- Save the updated PDF.
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 Radio Button Fields
def fill_radio_button_fields(infile, outfile):
"""Fill radio button fields in PDF form."""
# Create Form object
pdf_form = pdf_facades.Form()
# Bind PDF document
pdf_form.bind_pdf(infile)
# Fill radio button fields by name
pdf_form.fill_field("gender", 0) # Select male option (index 0)
# pdf_form.fill_field("gender", 1) # Select female option (index 1)
# Save updated PDF
pdf_form.save(outfile)