stapler icon indicating copy to clipboard operation
stapler copied to clipboard

Enhancement Request: fill_form functionality

Open shanemcquillan opened this issue 9 years ago • 8 comments

Hi. I'm wondering if you've given thought to, or considered adding the fill_form functionality of pdftk. I would be interested to know your thoughts on this.

shanemcquillan avatar Oct 22 '15 06:10 shanemcquillan

I haven't thought about it, because I never understood why it is useful. Can you explain what it is useful for? And the second question is, does PyPDF2 support that functionality? If not, it won't be in stapler.

hellerbarde avatar Oct 26 '15 09:10 hellerbarde

OK. I checked, the functionality is provided in PyPDF2, so this is maybe possible.

hellerbarde avatar Oct 26 '15 09:10 hellerbarde

You're correct. I actually found that and created a pull request for an extra function that will set these values across the entire document. Here's the forked version on my repo: https://github.com/mstamy2/PyPDF2 Should be very straight forward for you guys to add.

shanemcquillan avatar Oct 27 '15 05:10 shanemcquillan

A feature like this would be useful for filling forms that require similar content regularly.

shanemcquillan avatar Oct 27 '15 05:10 shanemcquillan

Agreeded. I too would like to see this functionality.

Others looking and want to take a stab at this: http://pythonhosted.org/PyPDF2/PdfFileWriter.html#PyPDF2.PdfFileWriter.updatePageFormFieldValues

smittysmee avatar Nov 16 '15 20:11 smittysmee

I've got a number of projects relying on pdftk to programmatically fill out user supplied PDF forms with database driven data. It's actually the only reason I use pdftk, and probably the only reason I'd use stapler (if it had the feature).

So +1.

Also, another requirement would be generate_fdf to create the FDF file from the PDF form file so that it can be passed to the fill_form command. We perform string replacement within the FDF file to enter mapped field values.

clphillips avatar Nov 18 '15 00:11 clphillips

Can you elaborate on that FDF file. Is that a common format? where can I find out more about it?

hellerbarde avatar Mar 18 '16 17:03 hellerbarde

Yes, FDF is a common format. Until recently it was the only format that could be used to fill forms for PDF documents. More info here, official spec here (starts on page 671).

It's a simple file format, and is primarily used with the following flow:

  1. Generate an FDF file from a PDF with form fields
  2. Programmatically modify the FDF file to populate form data
  3. Flatten the FDF and PDF into a new PDF document, which injects the form data and removes the form fields.

clphillips avatar Mar 18 '16 18:03 clphillips