hellerbarde / stapler

A small utility making use of the pypdf library to provide a (somewhat) lighter alternative to pdftk
Other
284 stars 53 forks source link

Enhancement Request: fill_form functionality #19

Open shanemcquillan opened 9 years ago

shanemcquillan commented 9 years ago

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.

hellerbarde commented 9 years ago

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 commented 9 years ago

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

shanemcquillan commented 9 years ago

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 commented 9 years ago

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

smittysmee commented 8 years ago

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

clphillips commented 8 years ago

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.

hellerbarde commented 8 years ago

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

clphillips commented 8 years ago

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.