PyPDFtk is a Python wrapper for the powerful command-line tool PDFtk (PDF Toolkit). It provides a Pythonic interface to manipulate PDF documents, enabling operations such as filling forms with data, concatenating multiple PDFs, splitting a single PDF into individual pages, extracting specific page ranges, replacing pages, generating XFDF data, stamping, and adding backgrounds. The library is currently at version 0.5, with its last release in April 2021, and primarily follows a maintenance release cadence.
pip install pypdftkVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic operations like getting the number of pages and concatenating PDFs using `pypdftk`. It highlights the necessity of the `pdftk` binary and provides comments on how to set `PDFTK_PATH`. A form-filling example is commented out as it requires a specific fillable PDF and proper `pdftk` configuration.
Install 'pdftk' (e.g., `sudo apt-get install pdftk` on Debian/Ubuntu, or download from pdflabs.com for other OSes). Ensure it's in your system's PATH, or set `os.environ['PDFTK_PATH'] = '/path/to/pdftk'` in your Python code.
Explicitly set the `PDFTK_PATH` environment variable in your script or shell to point to the `pdftk` executable, e.g., `os.environ['PDFTK_PATH'] = '/usr/local/bin/pdftk'`.
Always ensure the `out_dir` argument passed to `pypdftk.split()` is an empty directory or let the function use a temporary directory by omitting `out_dir`.
For operations involving image fields, consider alternative PDF manipulation libraries or tools that explicitly support image embedding, or pre-process PDFs with images before using PyPDFtk for form filling.
Install 'pdftk' on your operating system (e.g., `sudo apt-get install pdftk` on Debian/Ubuntu, `brew install pdftk-server` on macOS) and ensure it's in your system's PATH, or explicitly configure pypdftk with `pypdftk.configure(pdftk_path='/path/to/pdftk')`.
Install the library using pip: `pip install pypdftk`.
Verify that the file path is correct, the file exists, and your Python script has read/write permissions for the specified files and directories; use absolute paths for robustness.
Consult the `pypdftk` documentation for the correct function names and their usage, e.g., `pypdftk.fill_form`, `pypdftk.concat`, `pypdftk.split`.