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 programatically 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

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

Project details


Release history Release notifications | RSS feed

This version

0.0.8

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.8.tar.gz (6.5 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.8-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: PyPDFForm-0.0.8.tar.gz
  • Upload date:
  • Size: 6.5 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.8.tar.gz
Algorithm Hash digest
SHA256 2726864eb242e79cc863affed450d0898e0d100df345982cae38792b0f38598d
MD5 a2189363e7693e405b96d9b6c4124dc8
BLAKE2b-256 f2961c9c7ce8d346519cee87341bb5770f795c466e44a3437421600500a6de3f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: PyPDFForm-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 7.1 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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 89b0c9d6abbaa3137f55156a30bf264dd94ee9eb23fecfc4036061ca37c73731
MD5 47629c3fc32205c665e6586224c89f72
BLAKE2b-256 424b1393b1cd6ca0879c896a1b62988c668a09e89f29ebb5b00a96b2577718ef

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