Skip to main content

Use jinja templates to fill and sign pdf forms.

Project description

https://img.shields.io/badge/License-MIT%20License-blue.svg https://api.travis-ci.org/rammie/pdfjinja.png?branch=master

Use jinja templates to fill and sign PDF forms.

You can use this library to fill out a PDF form using data from an external source such as a database or an excel file. Use a PDF editing software to edit the form and specifiy a jinja template in the tooltip property of the form field.

Dependencies

You’ll need the pdftk library. If you want to paste images, you’ll need whatever dependencies are necessary for Pillow to load your preferred image format. Most of the packages below are taken from the Pillow documentation. You don’t need all of them. In most cases, just pdftk will do.

Ubuntu:

apt-get install python-dev python-pip libtiff5-dev libjpeg8-dev \
    zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev \
    tk8.6-dev python-tk pdftk libmagickwand-dev

OSX:

* Install pdftk (https://www.pdflabs.com/tools/pdftk-server/).
* Install dependencies for Pillow if you want to paste images.

Windows:

* Install pdftk (https://www.pdflabs.com/tools/pdftk-server/).
* Install dependencies for Pillow if you want to paste images.

Installation

You can install pdfjinja with pip:

$ pip install pdfjinja
$ pdfjinja -h

Usage:

See examples/sample.pdf for an example of a pdf file with jinja templates. The template strings are placed in the tooltip property for each form field in the pdf.

See examples/output.pdf for the output. The data that the form is filled with comes from examples/sample.json.

Basic:

$ pdfjinja -j examples/simple.json examples/sample.pdf examples/output.pdf

Attachments:

$ pdfjinja --font examples/open-sans/regular.ttf \
           --json examples/sample.json \
           examples/sample.pdf \
           examples/output.pdf

Python:

from pdfjinja import PdfJinja

pdfjinja = PdfJinja('form.pdf')
pdfout = pdfjinja(dict(firstName='Faye', lastName='Valentine'))
pdfout.write(open('filled.pdf', 'wb'))

If you are using this with Flask as a webserver:

from flask import current_app
from pdfjinja import PdfJinja
pdf = PdfJinja('form.pdf', current_app.jinja_env)

See examples/example.py for a more detailed python example. It might also be helpful to example the sample pdf template in examples/sample.pdf.

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

pdfjinja-1.1.0.tar.gz (432.1 kB view details)

Uploaded Source

File details

Details for the file pdfjinja-1.1.0.tar.gz.

File metadata

  • Download URL: pdfjinja-1.1.0.tar.gz
  • Upload date:
  • Size: 432.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.4

File hashes

Hashes for pdfjinja-1.1.0.tar.gz
Algorithm Hash digest
SHA256 678fe7eec9f46b48beb79c5f4d48a1668451ff1d5e447f05046621b20251e72e
MD5 619b291d20e9a0e55be88299476b41bb
BLAKE2b-256 b0f470e6f6b46478e69d06fec8aa28aaad21e60717d81f2112be7ed5898119ca

See more details on using hashes here.

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