Skip to main content

Extract and fill PDF AcroForm fields with a multi-backend fallback chain (pypdf, pdfrw, PyMuPDF, pdftk).

Project description

oc-pdf-filler

Extract and fill PDF AcroForm fields from the command line, with a multi-backend fallback chain so a single quirky PDF doesn't block your workflow.

The repo ships two artifacts:

  1. A Python package and CLI: oc-pdf-filler (subcommands: extract, fill, list-backends).
  2. An OpenClaw / AgentSkills skill at skills/pdf-filler/ that wraps the CLI so agents can use it.

Why a fallback chain?

PDF AcroForms are notoriously inconsistent. The orchestrator tries each backend in order and stops at the first one that fills every requested field:

  1. pypdf -- pure Python, required dependency.
  2. pdfrw -- fine-grained dictionary control (optional).
  3. PyMuPDF -- robust appearance regeneration, native checkbox/radio handling (optional).
  4. pdftk -- system binary, last resort (optional).

Backends without their dependency present are skipped automatically.

Install

pip install -e ".[all]"          # full fallback chain (pypdf + pdfrw + PyMuPDF)
# or, minimal:
pip install -e .                 # pypdf only
# Optional system dep:
brew install pdftk-java          # macOS
apt install pdftk-java           # Debian/Ubuntu

Verify your backends:

oc-pdf-filler list-backends

CLI usage

Extract a field schema

oc-pdf-filler extract form.pdf --output schema.json --include-values

Output is JSON with one entry per field:

{
  "field_count": 27,
  "fields": [
    {
      "name": "Name Verantwortlicher",
      "type": "text",
      "value": "ACME GmbH",
      "options": [],
      "max_length": null,
      "required": false,
      "multiline": false,
      "read_only": false
    }
  ]
}

type is one of text, checkbox, radio, choice, signature, pushbutton, unknown.

Fill a PDF

Build a JSON values file. Field names come from the schema verbatim.

{
  "Name Verantwortlicher": "ACME GmbH",
  "Postleitzahl Verantwortlicher": "10115",
  "Beschäftigte": true,
  "Verarbeitungstyp": "Automatisiert"
}

Then run:

oc-pdf-filler fill form.pdf values.json --output filled.pdf

Useful flags:

Flag Effect
--backend NAME Force one of pypdf / pdfrw / pymupdf / pdftk (default: auto)
--best-effort Chain backends so partial fills accumulate
--flatten Bake values into the PDF (best support: PyMuPDF, pdftk)
--strict Exit non-zero if any field is missing or unfillable

Value coercion per field type

Type JSON value
text string (newlines preserved when multiline is true)
checkbox true / false or "true", "yes", "on", "x", "1", "checked"
radio string equal to one of the entries in the field's options array
choice string equal to one of the dropdown options
signature not supported -- reported in the schema, ignored at fill time

Tests

pip install -e ".[dev]"
pytest -q

Tests run against the three real PDFs in test_pdfs/ and parametrize across every available backend. They round-trip text and checkbox values (fill, re-extract, assert).

OpenClaw skill

The skills/pdf-filler/ folder is an AgentSkills.io spec-compliant skill that an OpenClaw agent can load to get PDF-filling capabilities. It contains:

skills/pdf-filler/
├── SKILL.md                    # frontmatter + instructions
├── scripts/
│   ├── extract.py
│   ├── fill.py
│   └── list_backends.py
├── references/
│   ├── FIELD_TYPES.md
│   └── BACKENDS.md
└── assets/
    └── values.example.json

Validate it:

npx skills-ref validate ./skills/pdf-filler

Releasing a new version

Bump metadata.version in skills/pdf-filler/SKILL.md, then run:

clawhub publish ./skills/pdf-filler --version <semver>

--version is required and must be valid semver, and should match metadata.version so the registry record stays in sync.

The agent that loads the skill needs oc-pdf-filler installed in its workspace Python environment for the scripts to run; the skill's compatibility field documents this.

License

MIT

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

oc_pdf_filler-0.1.1.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oc_pdf_filler-0.1.1-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file oc_pdf_filler-0.1.1.tar.gz.

File metadata

  • Download URL: oc_pdf_filler-0.1.1.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for oc_pdf_filler-0.1.1.tar.gz
Algorithm Hash digest
SHA256 702bbc5a9938cf7112de14b711f397ca580e6f2a5041e0f1e2c0d4c60e9f55e4
MD5 ee0c91adc9f9335481d331816635c921
BLAKE2b-256 1b435d0a7548ec842b9fec0692f2fe24f07a7ad0927f443b8d135816c5a83d04

See more details on using hashes here.

File details

Details for the file oc_pdf_filler-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: oc_pdf_filler-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for oc_pdf_filler-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b2087360ae5069c0c9f234ac1c4e61cc83a6bb82e5a52f05dbf0cea69007faf6
MD5 92bd96356e4ca236d5db2e4b284f8bc9
BLAKE2b-256 3a01c7ebe290b9046674d394323e8ab59cce9c7be5cb8618f654820aa0720c3d

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