Skip to main content

pdfformfields

pdfformfields is a Python wrapper around pdftk that lets the user fill in forms from a Python dictionary.

Prerequisites

You need to have pdftk server on your computer installed.

Installing

To install, simply run

pip install pdfformfields

Usage

from pdfformfields import fill_form_fields, generate_dictionary


# Example pdf containing two fields with ids: first_name, last_name
example_input_pdf = "example_input.pdf"

# Use generate_dictionary() with verbose=True to understand the structure
# generate_dictionary(example_input_pdf, verbose=True)

# Use generate_dictionary() without verbose=True to generate a copiable code for the field dictionary onto the console
generate_dictionary(example_input_pdf)

""" The output should be:
rename_me = {
    "first_name": ,
    "last_name": ,
}
"""

# Paste code, rename dictionary, and fill in the values however you like
form_field_dictionary = {
    "first_name": "John",
    "last_name": "Doe",
}

# Output filled in dictionary with the fill_form_fields() function
example_output_pdf = r"example_output.pdf"
fill_form_fields(example_input_pdf, form_field_dictionary, example_output_pdf)

# If you don't want the output to be editable set flatten=True
example_output_pdf_flattened = r"example_output_pdf_flattened.pdf"
fill_form_fields(example_input_pdf, form_field_dictionary, example_output_pdf_flattened, flatten=True)

See complete example.

Bash error

The package did not manage to locate your pdftk command.

Make sure that pdftk server is installed on your system. If it is, try setting the pdftk argument of fill_form_fields to ...

... on Linux:

fill_form_fields(..., pdftk_command="pdftk")

... on Windows:

pdftk_path = os.path.join("path_to_pdftk_server_folder", "bin", "pdftk.exe")
fill_form_fields(..., pdftk_command=pdftk_path)

Built With

Author

  • Nguyen Ba Long

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details

Acknowledgments

  • pypdftk Inspiration: another wrapper around pdftk that does not work under Windows and Python 3.7, which is why this package was created.

Metadata

Release files for pdfformfields 0.0.3

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

Source distribution (sdist)

Source distribution for pdfformfields 0.0.3
File Size Uploaded
pdfformfields-0.0.3.tar.gz 4.3 kB Details

Built distribution (wheel)

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

Total release size: 21.7 kB

Release files / pdfformfields-0.0.3.tar.gz

Download URL pdfformfields-0.0.3.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
89013db34938138e9ebff940df3ca93bdd558b9988d7a8a2abb672bf3a02ab95
BLAKE2b-256 checksum
How to use checksums
4e154e85aa8e7b72726e83bcd6104a6f11d01f3ed587eaa6abfd48bb29ed2bdf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release files / pdfformfields-0.0.3-py3-none-any.whl

Download URL pdfformfields-0.0.3-py3-none-any.whl
Size 17.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0c0b04dd11142e7c1229167320a183c915f1fe3c59533577f7d912e6837f5495
BLAKE2b-256 checksum
How to use checksums
042ba4654f0a36facd5845644faf4638d7bee686bb55285689e9ce6a687c28d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

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