PyPDFForm

raw JSON →
4.8.2 verified Mon Apr 27 auth: no python

PyPDFForm is a Python library for programmatically filling, flattening, and manipulating PDF forms (AcroForms, XFA, etc.). Current version is 4.8.2, with active development and frequent releases (multiple versions per month). It supports Python >=3.10 and provides both a Python API and a CLI.

pip install pypdfform
error ImportError: cannot import name 'PdfWrapper' from 'pypdfform'
cause The internal package was restructured in v4.7.8; some users may have installed an older version that doesn't expose PdfWrapper.
fix
Upgrade to latest version: pip install --upgrade pypdfform
error KeyError: 'field_name'
cause The field name does not exist in the PDF form. PyPDFForm uses the original field names from the PDF.
fix
List all field names: pdf = PdfWrapper('template.pdf'); print(list(pdf.keys()))
breaking In v4.7.6 - v4.7.8, the internal package structure changed, moving source to lib/. Import paths from pypdfform remain the same, but if you relied on internal modules like pypdfform.egress or pypdfform.template, those imports will break. Use public API methods instead.
fix Use from pypdfform import PdfWrapper and avoid importing internal modules directly.
deprecated PdfWrapper.update_widget_key.defer parameter is deprecated since v4.7.7. It will be removed in a future version.
fix Remove defer parameter usage. If you need deferred operations, use the main update_field method without defer.
gotcha When filling checkboxes or radio buttons, use the field's export value (e.g., 'Yes' or 'On'), not a boolean True.
fix Check the widget's appearance dictionary; typically set pdf['checkbox_field'] = 'Yes' or pdf['radio_field'] = 'Choice1'.

Basic usage: open a template PDF, set form field values, and write output. Use flatten() to make fields non-editable.

from pypdfform import PdfWrapper

# Fill a PDF form
with open('template.pdf', 'rb') as f:
    pdf = PdfWrapper(f)
pdf['field_name'] = 'value'
with open('output.pdf', 'wb') as f:
    f.write(pdf.read())

# Flatten the form (remove interactivity)
pdf.flatten()
with open('output_flattened.pdf', 'wb') as f:
    f.write(pdf.read())