I needed to fill in a PDF form recently (the proper editable sort, not a flat PDF with empty spaces); me being me I wanted to use Free tools, and ideally do so in a way that I could use version control on the bits I was adding to the form.
Thankfully, with
As an example form, here's a publically-available one. If you run
An excerpt:
So if you put some text in the parentheses above "In the", then that text appears in the relevant box on the form. In this case, it's pretty obvious where on the form that's going to be, but not all the fields are so obvious - where is
You can, obviously, put dummy data in each place, fill the form out and observe the results. That's fine, but obviously doesn't help with the Check Boxes. To find out more, you want
From this, we can see that
So you can edit everything into the FDF file, and keep it in git (and get useful diffs), and then turn it into a filled-out PDF with
Thankfully, with
pdftk, this is pretty doable. It was mostly only a bit fiddly because there wasn't a coherent answer to some of the edge cases (e.g. round tick boxes). Basically, the process is:pdftk generate_fdfto get the file you want to editpdftk dump_data_fieldsif necessary to learn about tickboxes- edit the fdf file
pdftk fill_formto fill the form in
As an example form, here's a publically-available one. If you run
pdftk n1-eng.pdf generate_fdf output fields.fdf, you get an .fdf (Form Data Format) file. It looks a bit weird, but basically you can edit the relevant bits of contents as text.An excerpt:
<< /V () /T (In the) >> << /V / /T (Check Box34) >>
So if you put some text in the parentheses above "In the", then that text appears in the relevant box on the form. In this case, it's pretty obvious where on the form that's going to be, but not all the fields are so obvious - where is
Text28, for example?You can, obviously, put dummy data in each place, fill the form out and observe the results. That's fine, but obviously doesn't help with the Check Boxes. To find out more, you want
pdftk dump_data_fields, which includes for this form:--- FieldType: Text FieldName: Text28 FieldNameAlt: Brief details of claim FieldFlags: 12587008 FieldJustification: Left --- FieldType: Button FieldName: Check Box34 FieldFlags: 0 FieldJustification: Left FieldStateOption: Off FieldStateOption: tickbox No - Does, or will, your claim include any issues under the Human Rights Act 1998? FieldStateOption: tickbox Yes - Does, or will, your claim include any issues under the Human Rights Act 1998? ---
From this, we can see that
Text28 is where we put the "Brief details of claim". It also tells us how to tick the relevant tickbox about the HRA 1998, though it's a bit non-obvious. What you do is include the entire FieldStateOption of the box you want, thus:<< /V (tickbox No - Does, or will, your claim include any issues under the Human Rights Act 1998?) /T (Check Box34) >>
So you can edit everything into the FDF file, and keep it in git (and get useful diffs), and then turn it into a filled-out PDF with
pdftk form.pdf fill_form data.fdf output form.filled.pdf - the form is neatly filled out, including the tick-boxes!
(no subject)