Skip to main content

python library for PDF forms

Project description

PyPDFForm

PyPDFForm is a pure-python library for PDF form processing. It allows filling a PDF form programmatically by creating a python dictionary with keys matching its annotation names for elements like text fields and checkboxes. It also supports other functionalities such as drawing image and merging multiple PDFs together.

Installing

Install using pip:

pip install PyPDFForm

Quick Example

A sample PDF form can be found here. Download it and try:

import os

from PyPDFForm import PyPDFForm

PATH_TO_DOWNLOADED_SAMPLE_PDF_FORM = os.path.join(
    os.path.expanduser("~/Downloads"), "sample_template.pdf"
)  # Change this to where you downloaded the sample PDF form

PATH_TO_FILLED_PDF_FORM = os.path.join(
    os.path.expanduser("~"), "output.pdf"
)  # Change this to where you wish to put your filled PDF form

with open(PATH_TO_DOWNLOADED_SAMPLE_PDF_FORM, "rb+") as template:
    filled_pdf = PyPDFForm(template.read(), simple_mode=False).fill(
        {
            "test": "test_1",
            "check": True,
            "test_2": "test_2",
            "check_2": False,
            "test_3": "test_3",
            "check_3": True,
        },
        font_size=20,
    )

    with open(PATH_TO_FILLED_PDF_FORM, "wb+") as output:
        output.write(filled_pdf.stream)

After running the above code snippet you can find output.pdf at the location you specified and it should look like this.

Documentation

Tests

PyPDFForm utilizes pytest for unit and functional tests. Tests can be run by first installing dependencies using pip:

pip install -r requirements.txt

Alternatively, there is a bash script which will setup a python virtual environment and install all needed dependencies if you are running Linux:

./scripts/build.sh

In order to run tests, source root needs to be added to PYTHONPATH by running the following command at project root:

export PYTHONPATH=$PYTHONPATH:$(pwd)/PyPDFForm

From there run tests using:

pytest -v

Or you can use this bash script to do the above two steps if you are running Linux:

./scripts/test.sh

Project details


Release history Release notifications | RSS feed

This version

0.0.9

Download files

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

Source Distribution

PyPDFForm-0.0.9.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

PyPDFForm-0.0.9-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file PyPDFForm-0.0.9.tar.gz.

File metadata

  • Download URL: PyPDFForm-0.0.9.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for PyPDFForm-0.0.9.tar.gz
Algorithm Hash digest
SHA256 5792e5487f64f3fa496a4397fd8f81e31e42502d0da7bca08d3b3b0f7ca40710
MD5 c6d1ae6494652e04bc5533690789a4ef
BLAKE2b-256 3bf846be0b007f6dcb402a94e75dc814a27cc1d17cebcb92d8162f5f40759f20

See more details on using hashes here.

File details

Details for the file PyPDFForm-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: PyPDFForm-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for PyPDFForm-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 64838e72d8f2699dfee6bdf934532e34d506d761815db4aacdd322311509c8fc
MD5 4ddc0c38fc4974283f0a6602771851c7
BLAKE2b-256 8bfc69f060e77a0c3e3ec8e0c06eda1240a205862b56f88650e01b470f33afc0

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