# 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](https://pip.pypa.io/en/stable/quickstart/):
```shell script
pip install PyPDFForm
```
## Quick Example
A sample PDF form can be found [here](https://github.com/chinapandaman/PyPDFForm/blob/master/pdf_samples/v2/sample_template.pdf). Download it and try:
```python
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,
global_font_size=20,
).fill(
{
"test": "test_1",
"check": True,
"test_2": "test_2",
"check_2": False,
"test_3": "test_3",
"check_3": True,
},
)
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](https://github.com/chinapandaman/PyPDFForm/blob/master/pdf_samples/v2/sample_filled_font_20.pdf).
## Documentation
* API Reference: https://github.com/chinapandaman/PyPDFForm/blob/master/docs/v2/api_reference.md
* API Reference (legacy): https://github.com/chinapandaman/PyPDFForm/blob/master/docs/api_reference.md
* Examples: https://github.com/chinapandaman/PyPDFForm/blob/master/docs/v2/examples.md
* Examples (legacy): https://github.com/chinapandaman/PyPDFForm/blob/master/docs/examples.md
## Tests
PyPDFForm utilizes [pytest](https://docs.pytest.org/en/stable/) for unit and
functional tests. Tests can be run by first installing dependencies using
[pip](https://pip.pypa.io/en/stable/quickstart/):
```shell script
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:
```shell script
make build
```
In order to run tests, source root needs to be added to PYTHONPATH by running
the following command at project root:
```shell script
export PYTHONPATH=$PYTHONPATH:$(pwd)/PyPDFForm
```
From there run tests using:
```shell script
pytest -v
```
Or you can use this Makefile rule to do the above two steps if you are running Linux:
```shell script
make test
```
Raw data
{
"_id": null,
"home_page": "https://github.com/chinapandaman/PyPDFForm",
"name": "PyPDFForm",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "",
"author": "",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/d0/2f/5162ec10f9ed6282662bd965b587e12eb7e8390b627bbc05015a56cec76c/PyPDFForm-0.2.0.tar.gz",
"platform": "",
"description": "# PyPDFForm\n\nPyPDFForm is a pure-python library for PDF form processing. \nIt allows filling a PDF form programmatically by creating \na python dictionary with keys matching its annotated names \nfor elements like text fields and checkboxes. It also supports other functionalities such as \ndrawing image and merging multiple PDFs together.\n\n## Installing\n\nInstall using [pip](https://pip.pypa.io/en/stable/quickstart/):\n\n```shell script\npip install PyPDFForm\n```\n\n## Quick Example\n\nA sample PDF form can be found [here](https://github.com/chinapandaman/PyPDFForm/blob/master/pdf_samples/v2/sample_template.pdf). Download it and try:\n\n```python\nimport os\n\nfrom PyPDFForm import PyPDFForm\n\nPATH_TO_DOWNLOADED_SAMPLE_PDF_FORM = os.path.join(\n os.path.expanduser(\"~/Downloads\"), \"sample_template.pdf\"\n) # Change this to where you downloaded the sample PDF form\n\nPATH_TO_FILLED_PDF_FORM = os.path.join(\n os.path.expanduser(\"~\"), \"output.pdf\"\n) # Change this to where you wish to put your filled PDF form\n\nwith open(PATH_TO_DOWNLOADED_SAMPLE_PDF_FORM, \"rb+\") as template:\n filled_pdf = PyPDFForm(\n template.read(),\n simple_mode=False,\n global_font_size=20,\n ).fill(\n {\n \"test\": \"test_1\",\n \"check\": True,\n \"test_2\": \"test_2\",\n \"check_2\": False,\n \"test_3\": \"test_3\",\n \"check_3\": True,\n },\n )\n\n with open(PATH_TO_FILLED_PDF_FORM, \"wb+\") as output:\n output.write(filled_pdf.stream)\n```\n\nAfter running the above code snippet you can find `output.pdf` at the location you specified, \nand it should look like [this](https://github.com/chinapandaman/PyPDFForm/blob/master/pdf_samples/v2/sample_filled_font_20.pdf).\n\n## Documentation\n\n* API Reference: https://github.com/chinapandaman/PyPDFForm/blob/master/docs/v2/api_reference.md\n* API Reference (legacy): https://github.com/chinapandaman/PyPDFForm/blob/master/docs/api_reference.md\n* Examples: https://github.com/chinapandaman/PyPDFForm/blob/master/docs/v2/examples.md\n* Examples (legacy): https://github.com/chinapandaman/PyPDFForm/blob/master/docs/examples.md\n\n## Tests\n\nPyPDFForm utilizes [pytest](https://docs.pytest.org/en/stable/) for unit and \nfunctional tests. Tests can be run by first installing dependencies using \n[pip](https://pip.pypa.io/en/stable/quickstart/):\n\n```shell script\npip install -r requirements.txt\n```\n\nAlternatively, there is a Makefile rule which will set up a python virtual environment \nand install all needed dependencies if you are running Linux:\n\n```shell script\nmake build\n```\n\nIn order to run tests, source root needs to be added to PYTHONPATH by running \nthe following command at project root:\n\n```shell script\nexport PYTHONPATH=$PYTHONPATH:$(pwd)/PyPDFForm\n```\n\nFrom there run tests using:\n\n```shell script\npytest -v\n```\n\nOr you can use this Makefile rule to do the above two steps if you are running Linux:\n\n```shell script\nmake test\n```\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "python library for PDF forms",
"version": "0.2.0",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "39f8fd7779960cf4170d6c58936ed402",
"sha256": "3d871006701aa1df8b784be892ce6fb03110028c381a46e335c6b98fd100180a"
},
"downloads": -1,
"filename": "PyPDFForm-0.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "39f8fd7779960cf4170d6c58936ed402",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 21166,
"upload_time": "2020-12-22T01:43:57",
"upload_time_iso_8601": "2020-12-22T01:43:57.966897Z",
"url": "https://files.pythonhosted.org/packages/5b/c0/214ea422c3fb1b2e280459c3d03317f344ab835f37dd4aa4d18266c8fb70/PyPDFForm-0.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "263a4401db0a8620f414288133ea230c",
"sha256": "22b4b54ebb21de7826c9e141bdc92ab553c1b626675d42fa5ab369eb1f552267"
},
"downloads": -1,
"filename": "PyPDFForm-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "263a4401db0a8620f414288133ea230c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 14044,
"upload_time": "2020-12-22T01:43:58",
"upload_time_iso_8601": "2020-12-22T01:43:58.989746Z",
"url": "https://files.pythonhosted.org/packages/d0/2f/5162ec10f9ed6282662bd965b587e12eb7e8390b627bbc05015a56cec76c/PyPDFForm-0.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2020-12-22 01:43:58",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": null,
"github_project": "chinapandaman",
"error": "Could not fetch GitHub repository",
"lcname": "pypdfform"
}