Skip to main content

A library and command-line tool for working with PDF interactive forms. Uses pikepdf and pdf2htmlex.

Reason this release was yanked:

broken

Project description

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())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdform-0.2.3.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pdform-0.2.3-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file pdform-0.2.3.tar.gz.

File metadata

  • Download URL: pdform-0.2.3.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.12 Linux/4.18.0-553.105.1.el8_10.x86_64

File hashes

Hashes for pdform-0.2.3.tar.gz
Algorithm Hash digest
SHA256 897dea2bc6c7ce3b2b7a93296c305acc884ec11b9d495ac55051635b0b0443f8
MD5 8048bd6aa8620a51bceb6cac59841e7d
BLAKE2b-256 5b8521cf6aeed663a4febdd1a9bd1295d6c27bdbe2a55189dc4ccf45292725d3

See more details on using hashes here.

File details

Details for the file pdform-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: pdform-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.12 Linux/4.18.0-553.105.1.el8_10.x86_64

File hashes

Hashes for pdform-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ffbc643ac92ed8bc5171f2f87a65fe68513fd4bc434f4a2d2c877855d6ebafd2
MD5 3b23725c19eb5c8921a02c6b2eb53d5a
BLAKE2b-256 3f5af80c9c16a60d7d4d5fe7ce9d426ed0801cdd0d9c69d2a38073fcd3f34f7d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page