Skip to main content

PDForm

A library and command-line tool for working with PDF interactive forms. It can:

  • Describe the available fields in the form

  • Convert the PDF to an HTML form

  • Populate the PDF form with data

Uses Pikepdf.

Describing Forms

The pdform describe command can be used to get information about a PDF form, such as the names and types of fields, allowable options, and so forth. Use pdform describe –help for command-line options.

pdform describe form.pdf

By default, it will show every field in the form, together with all the relevant details about the field. Command-line options exist to filter this view for easier parsing.

=========================================================================
stream <_io.BufferedReader name='../../pikepdf/tests/resources/form.pdf'>
=========================================================================

Text1
-----

Label:
        Text1

Type:
        TextField

Required:
        No

Read Only:
        No

Multiline:
        No

Max Length:
        None

Default Value:


Current Value:

... and so on ...

Filling Forms

Filling forms is done using the pdform fill-form command. Typically, this will be done using JSON-formatted data, such as:

{
    "TextField1": "Some Text",
    "Checkbox1": true,
    "RadioGroup1": "3",
    "ChoiceField1": "Option 4",
    "SignatureField": "/home/myself/signature.png"
}

You can then call the command with this JSON:

pdform fill-form template.pdf output.pdf data.json

Or pipe this JSON into the command:

echo {your json here} | pdform fill-form template.pdf output.pdf -

Converting to HTML

Converting to HTML relies on pdf2htmlEX to generate the initial HTML. We then use BeautifulSoup to strip away most of the unnessesary code, and add the form fields.

This function can be activated in one of two ways:

  1. The pdform make-html command. Use pdform make-html –help for details.

  2. Directly via Python.

The command-line interface is sufficient for basic usage. It provides a handful of different output formats: plain HTML, Jinja, and PHP.

pdform make-html --jinja input.pdf output.jinja

However, it is likely you may wish to customize the rendered HTML. The Python interfaces gives much more flexibility for this.

from pdform.make_html import FieldRenderer, make_html

# Define your own field renderer to control the emitted code for form fields
class MyFieldRenderer(FieldRenderer):
    # See the source code for details on how to implement this class
    ...

soup = make_html(path, field_renderer_class=MyFieldRenderer)
# Use the BeautifulSoup object to perform any post-processing to the generated HTML
# (See the BeautifulSoup documentation for how to use it to manipulate the DOM)
...
# Output the rendered HTML
print(soup.prettify())

Metadata

Release files for pdform 0.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pdform 0.2.5
File Size Uploaded
pdform-0.2.5.tar.gz 11.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pdform 0.2.5
File Interpreter ABI Platform
pdform-0.2.5-py3-none-any.whl Python 3 none any Details

Total release size: 25.8 kB

Release files / pdform-0.2.5.tar.gz

Download URL pdform-0.2.5.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c861e16f7bc4c5ec5ce56717765e8f450fa6b3098c016b2808c7f703957282a9
BLAKE2b-256 checksum
How to use checksums
42cae9098f8a3c2c6adbfdfa133f6a164f3a522976925d919ee5684ffd485ca3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.1 CPython/3.12.12 Linux/4.18.0-553.105.1.el8_10.x86_64

Release files / pdform-0.2.5-py3-none-any.whl

Download URL pdform-0.2.5-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a4d4d7a65dd6b9c5b6870fd1b7e9e21bffbb10558c4731a671d20457a4b88d40
BLAKE2b-256 checksum
How to use checksums
c43f376e2d3002dd438d530b93591e863fad7d714e88b474d5d0dbb8a72da121
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.1 CPython/3.12.12 Linux/4.18.0-553.105.1.el8_10.x86_64

Release history Release notifications | RSS feed

This release

0.2.5 This release

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page