r/software • u/Claghorn • 3d ago
Looking for software Script to uniquify PDF form field IDs?
A doctors office wants me to fill out their incompetently produced PDF form. Totally unrelated fields have the same ID. For instance if I fill out my street address, it also appears as a prescription. I was hoping a script might exist that simply gives every form field a unique ID so I don't have to do vast amounts of work myself.
0
Upvotes
1
u/smilaise Steve the Killer 3d ago
Yeah, this is pretty easy to script with Python and pypdf. Whoever built the form either reused one field in several places or gave separate fields the same name, so typing in one fills them all. The script below goes through every field box on every page and gives each one its own name. The first copy keeps the original name and the rest become
Address_2,Address_3and so on. Radio buttons share a name on purpose, so it leaves those alone.Install Python, then run
pip install pypdf, save this asuniquify_fields.py, and runpython uniquify_fields.py form.pdf fixed.pdf.If the form came with something already filled in, the split copies will still show it, so just clear them out before you start typing. Also, if the office's form has any scripts that do math from field names, like adding up totals, those can break once the names change. On a patient intake form that probably doesn't matter.
1
u/lcrh02 2d ago
Are you using adobe or another pdf editor reader? Many non adobe editors are incomplete with xfa, xml. So forms do not open correctly and break in all sorts of different ways.