Repository navigation
Conversation
Introduces PDF_Forms/ — a self-contained Python toolkit that
automatically populates fillable PDF forms from structured data.
Files added:
- fill_pdf_form.py – main CLI: inspect fields, single-fill (JSON /
inline key=value), and batch-fill from CSV
- requirements.txt – single dependency: pypdf>=4.0.0
- create_sample_form.py – helper to generate a test fillable PDF via
reportlab (not required at runtime)
- sample_data.json – example single-record data file
- sample_batch.csv – example multi-record batch file
- sample_form.pdf – pre-built test template with 9 AcroForm fields
Usage summary:
python3 fill_pdf_form.py --inspect template.pdf
python3 fill_pdf_form.py template.pdf --data data.json
python3 fill_pdf_form.py template.pdf --set 'Name=Alice' --set 'City=NY'
python3 fill_pdf_form.py template.pdf --csv records.csv --output-dir ./out/
Co-authored-by: Bo Watts <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a self-contained Python toolkit under
PDF_Forms/that automates populating fillable PDF forms when the field data is provided. Only one runtime dependency is needed:pypdf.New files
PDF_Forms/fill_pdf_form.pyPDF_Forms/requirements.txtpypdf>=4.0.0)PDF_Forms/sample_data.jsonPDF_Forms/sample_batch.csvPDF_Forms/sample_form.pdfPDF_Forms/create_sample_form.pyreportlab)Usage
Install
1 — Discover what fields a PDF has
Output example:
2 — Fill from a JSON file
data.jsonis a flat{ "FieldName": "value" }object. Unknown keys are silently ignored so one data file can target multiple templates.3 — Fill with inline key=value pairs
4 — Batch fill from a CSV (one PDF per row)
CSV headers must match the PDF field names exactly. Output files are named
<template>_<FirstValue>_<SecondValue>.pdffor easy identification.Implementation notes
PdfWriter.append()to clone the full document (pages + AcroForm metadata) before callingupdate_page_form_field_values()— this is the correct pypdf pattern that preserves form field annotations in the output.