The Python library for PDF forms.
Project description
Important API Changes
Happy new year fellow developers! We start the year 2024 with a new release of v1.4.0 and there are some important changes I'm making to the APIs of the library.
- The PDF object that gets instantiated is now
PyPDFForm.PdfWrapper
, changed fromPyPDFForm.PyPDFForm
. - Form widgets are now accessed via the
PdfWrapper.widgets
attribute, changed fromPdfWrapper.elements
. - The JSON schema of the form data is now accessed via a new attribute called
PdfWrapper.schema
, changed from the old method ofPdfWrapper.generate_schema()
.
All the old APIs will be persisted for half a year and then fully deprecated. Each of them
will emit a DeprecationWarning
when invoked, so it is advised that you make the switch before they are
removed and start breaking your code.
Happy hacking!
Introduction
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 widgets 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 PdfWrapper
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(
PdfWrapper(PATH_TO_DOWNLOADED_SAMPLE_PDF_FORM)
.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
Public Speak
Chicago Python User Group - Dec 14, 2023
How to Contribute
It is difficult to make sure that the library supports all the PDF form creating tools out there. So if you run into a case where the library does not work for certain PDF forms created by certain tools, feel free to open an issue with the problematic PDF form attached. I will seek to make the library support the attached PDF form as well as the tool used to create it.
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
Built Distribution
Hashes for PyPDFForm-1.4.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6924ce02572286c406bcea2b2432b9dcf82978e25aa95364efdefe9f29bcf61a |
|
MD5 | 50a176ff93bea759b61fba0f554fd3bf |
|
BLAKE2b-256 | b3713e0c46e4ce6a248b6c981dd8a215bdc8efb4d7aabe7d24c0bddbaf3a4f18 |