Fill a PDF form from a spreadsheet
Somebody in every office types the same form dozens of times a week: name, date, amount, repeat. The data already lives in a spreadsheet. form --fill-from is mail-merge for PDF forms: one filled PDF per row, filed by any column.
How to do it
pip install pdfblah
# 1. see what the form calls its fields
pdfblah form expense.pdf --list
# Employee (text) = ''
# Amount (text) = ''
# 2. a CSV whose headers match
# Employee,Amount
# Ada Lovelace,120.50
# Grace Hopper,99.00
# 3. one filled PDF per row, named by employee
pdfblah form expense.pdf --fill-from rows.csv -o filled/ --name "{Employee}.pdf"
filled 2 cop(ies) into filled/ (fields: Amount, Employee)
The details that behave
- Columns that match no field are reported once, by name, instead of silently dropped. You find the typo in the header, not in the printed stack.
- JSON works too (an array of objects), for data coming out of a script or export.
- --flatten bakes the values in so the copies are no longer editable forms; leave it off and they stay fillable.
- Filenames from data are neutered against path tricks, and duplicate names get suffixes (
Sam.pdf,Sam-2.pdf).
Tips
- Checkboxes fill with true/false-ish values (yes, 1, true check the box; off, 0, empty leave it).
- No form fields in your PDF? It's a flat document; the form version of it (or a fillable rebuild) has to come first.
pdfblah form in.pdf --listtells you which kind you have. - Combine with batch afterwards to stamp, number, or sanitize the filled set in one pass.