Skip to content

Instantly share code, notes, and snippets.

@peteristhegreat
Created August 23, 2021 17:08
Show Gist options
  • Save peteristhegreat/0bb67b74754f5cd3e31bf7ab7e8ad4c2 to your computer and use it in GitHub Desktop.
Save peteristhegreat/0bb67b74754f5cd3e31bf7ab7e8ad4c2 to your computer and use it in GitHub Desktop.
Filling PDFs, python, pypdftk example and other links

https://yoongkang.com/blog/pdf-forms-with-python/

https://github.com/t-houssian/fillpdf

https://github.com/ccnmtl/fdfgen/

https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/

https://github.com/revolunet/pypdftk

https://answers.acrobatusers.com/export-fdf-Acrobat-DC-q274790.aspx

For my recent python + pdf form filling experience, I did an install of pdftk, and then used the pypdftk library.

To get the list of fillable fields out of the form use:

from ppretty import ppretty
import pypdftk

os.environ['PDFTK_PATH'] = "C:/Program Files (x86)/PDFtk/bin"

template_form = 'path/to/template.pdf'

data_fields = pypdftk.dump_data_fields(template_form)
print(ppretty(data_fields, seq_length=100))

Then to actually fill it in, drop in an appropriate dictionary and put it in this:

filled_form = 'path/to/filled/form_' + timestamp_str + '.pdf'
generated_pdf = pypdftk.fill_form(template_form, datas, out_file=filled_form, flatten=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment