Skip to main content

The 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 annotated 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_FILLED_PDF_FORM, "wb+") as output:
    output.write(
        PyPDFForm(
            PATH_TO_DOWNLOADED_SAMPLE_PDF_FORM, simple_mode=False, global_font_size=20,
        )
        .fill(
            {
                "test": "test_1",
                "check": True,
                "test_2": "test_2",
                "check_2": False,
                "test_3": "test_3",
                "check_3": True,
            },
        )
        .read()
    )

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 Makefile rule which will set up a Python virtual environment and install all needed dependencies if you are running Linux:

make build-all

Activate your virtual environment and run tests using:

pytest -v

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

make test-all

Project details


Release history Release notifications | RSS feed

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.3.5.tar.gz (15.7 kB view hashes)

Uploaded Source

Built Distribution

PyPDFForm-0.3.5-py3-none-any.whl (23.4 kB view hashes)

Uploaded Python 3

Supported by

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