| name | form-filler |
| description | Fill PDF forms programmatically with data from JSON, CSV, or dictionaries. Support for text fields, checkboxes, and dropdowns. Batch filling available. |
Form Filler
Fill PDF forms programmatically with structured data.
Features
- Field Detection: Auto-detect form fields
- Multiple Field Types: Text, checkbox, dropdown, radio
- Data Sources: JSON, CSV, dictionary input
- Batch Filling: Fill multiple forms from data file
- Field Mapping: Map data keys to field names
- Flatten Option: Convert to non-editable PDF
- Form Info: List all fields and their types
Quick Start
from form_filler import FormFiller
filler = FormFiller()
filler.load("application_form.pdf")
filler.fill({
"name": "John Doe",
"email": "john@example.com",
"date": "2024-01-15",
"agree": True
})
filler.save("filled_form.pdf")
CLI Usage
python form_filler.py --input form.pdf --data data.json --output filled.pdf
python form_filler.py --input form.pdf --list-fields
python form_filler.py --input form.pdf --batch data.csv --output-dir filled/
python form_filler.py --input form.pdf --data data.json --flatten --output filled.pdf
python form_filler.py --input form.pdf --data data.json --mapping mapping.json -o filled.pdf
API Reference
FormFiller Class
class FormFiller:
def __init__(self)
def load(self, filepath: str) -> 'FormFiller'
def list_fields(self) -> List[Dict]
def get_field_info(self, field_name: str) -> Dict
def get_field_value(self, field_name: str) -> Any
def fill(self, data: Dict) -> 'FormFiller'
def fill_field(self, name: str, value: Any) -> 'FormFiller'
def fill_from_json(self, filepath: str) -> 'FormFiller'
def fill_from_csv_row(self, row: Dict) -> 'FormFiller'
def set_mapping(self, mapping: [, ]) ->
() ->
() ->
() -> []
Field Types
Text Fields
filler.fill({
"first_name": "John",
"last_name": "Doe",
"address": "123 Main St"
})
Checkboxes
filler.fill({
"agree_terms": True,
"subscribe": False
})
Radio Buttons
filler.fill({
"gender": "male",
"payment_method": "credit_card"
})
Dropdowns
filler.fill({
"country": "USA",
"state": "California"
})
Field Discovery
fields = filler.list_fields()
Field Mapping
Map data keys to form field names:
filler.set_mapping({
"fname": "first_name",
"lname": "last_name",
"addr": "address_line_1"
})
filler.fill({
"fname": "John",
"lname": "Doe"
})
Batch Filling
From CSV
filler.batch_fill(
input_form="application.pdf",
data_file="applicants.csv",
output_dir="filled_forms/"
)
From JSON Array
filler.batch_fill(
input_form="form.pdf",
data_file="data.json",
output_dir="output/"
)
Dependencies
- PyMuPDF>=1.23.0
- pillow>=10.0.0
- pandas>=2.0.0