How to Fill PDF Form Drop-Down Lists using PHP and FDF
Question details
The user wants to dynamically populate drop-down fields in a PDF form using PHP string operations, FDF data, or PDFtk.

- Product
- Device & OS
- not provided
- Scenario
- Automating the population of PDF form drop-down fields via server-side processing.
- Observed behavior
- To display correctly, the injected FDF data must exactly match the field's export value or a predefined list item.
Ensure you have the exact export values for the drop-down fields defined in your source PDF form, as the injected FDF data must match these values perfectly to function.
Generate and Merge FDF Data using PHP
Create a plain text FDF file using PHP string operations and merge it server-side to populate the PDF drop-down list.
FDF (Forms Data Format) is a standard way to handle data submitted from or to PDF forms. By using PHP, you can programmatically generate an FDF file that targets specific drop-down fields in your PDF. Because client-side FDF handling varies greatly across modern browsers, merging the data server-side using tools like PDFtk is the most reliable approach.
Open your original PDF form in a PDF editor, enter form editing mode, and check the properties of the drop-down list to record the exact export values for each option.
Use PHP string operations to format your FDF data structure. Assign the desired export value to the specific field name corresponding to your drop-down list.
Save the generated FDF string as a temporary .fdf file on your server.
Use a server-side command line tool like PDFtk to merge the FDF file with the original PDF document. For example: 'pdftk original.pdf fill_form data.fdf output final.pdf'.
Open the resulting PDF in various target PDF viewers to confirm that the drop-down list item is selected and displays the correct value.
Manage and Test PDF Forms with WPS Office
Before automating form filling with PHP and FDF, you need a properly structured PDF form. WPS Office provides a comprehensive PDF editor to easily create drop-down lists, define exact export values, and test your forms manually.
- 1. Open PDF in WPS Office: Launch WPS Office and open the PDF document you want to prepare.
- 2. Navigate to Form Tools: Click on the 'Form' tab located in the top navigation ribbon.
- 3. Select the Drop-down Field: Click to add a new drop-down form field, or select an existing one.
- 4. Define Export Values: Right-click the field, select 'Properties', and navigate to the options tab to define your list items and their exact export values.
- 5. Save the Document: Save the updated PDF form to your computer for use in your server-side PHP processing.

Frequently Asked Questions
Why is my PDF drop-down field blank after merging FDF data?
This typically occurs when the value submitted in the FDF file does not exactly match the export value defined for the drop-down list in the PDF. Double-check your PDF form properties and correct the assigned value in your PHP script.
Can I rely on client-side FDF merging in web browsers?
Client-side processing is largely unreliable because different browsers use custom built-in PDF viewers that may not fully support FDF parsing. Server-side merging using tools like PDFtk is strongly recommended to ensure consistent results.
How do I find the export values of a PDF drop-down list?
You need to open the PDF in a capable PDF editor (such as WPS Office), enter the Form editing mode, right-click the drop-down field to open its properties, and view the options tab where item names and their corresponding export values are listed.




