Index

How to fill a PDF form with pdftk

I had a rather lenghty PDF form to fill, it took me 2 hours to do it becuase copy-pasting didn’t work in with my PDF editor.

After I saved the file I realized that I clicked on a radio button I shouldn’t have clicked on: Kids. I do not have kid, and the radio selection didn’t contain the zero option, only one and more. After trying to get rid of that radio selection for 5 minutes, it looked like there was no way to undo this: I had selected something I couldn’t unselect.

I didn’t want to waste another 2 hours to fill out the form, I needed to fix this by editing the PDF.

After a bit of googling I found pdftk, a command-line toolkit that can fill & extract information out of PDF forms.

To unselect the radio box, I had to extract the form data. Pdftk can extract the information into a text file that you can edit with a text editor.

pdftk input.pdf generate_fdf output form_data.fdf

Here it will generate form_data.fdf from input.pdf’s form values. After that I had to modify the fdf file to get rid of my selection. In my case, I wanted to reset the selection for the Kids radio selection.

/Kids [
<<
/V (1)
/T (RadioButtonList[0])
>>]

I changed it from “1 kid” to “nothing selected”.

/Kids [
<<
/V /Off
/T (RadioButtonList[0])
>>]

Then I had to re-enter the information from the FDF file into the PDF.

pdftk input.pdf fill_form form_data.fdf output output.pdf

It took me around an hour to do all this, so pdftk saved me time. I liked it, you can check out pdftk’s own examples to learne more, the documentation is terse and complete.