Skip to main content

formalpdf

formalpdf is an Apache-licensed python library for PDF forms. It's a unified API for extracting, creating, filling, and flattening forms. It has a similar, but not drop-in, high-level API to PyMuPDF. All of this is possible by wrapping pdfium, thanks to the low-level bindings made available through pypdfium2.

Installation

Using uv

uv pip install formalpdf

Using pip

pip install formalpdf

CLI Usage

🚧 Soon you can use formalpdf to fill a PDF from an FDF document using:

formalpdf fill <input.pdf> <input.fdf> <output.pdf>

Programmatic Usage

Get All Widget Objects in a PDF

import formalpdf

doc = formalpdf.open("path/to/document.pdf") 

for page in doc:
    widgets = page.widgets()

A Widget object has information about the location, type, and contents of form fields/wdigets in the PDF. For isntance, a widget might look like:

Widget(
    # name of the widget
    field_name='Text110',
    # label/alternate name, if provided
    field_label='Date (MM/DD/YYYY)',
    # current value (always a string, even if checkbox or combobox)
    field_value='',
    # widget type enum value
    field_type=6,
    # widget type string value 
    field_type_string='Text',
    # widget location Rect
    rect=Rect(
        top=36.95610046386719,
        left=473.5320129394531,
        bottom=24.171100616455078,
        right=587.177978515625
    )
)

Filling out Forms: Updating Widget Values

Let's say we had some textbox widget:

w = doc[0].widgets()[0]

We can update it with:

w.update("New Value")

doc.save("new_doc.pdf")

And when we open new_doc.pdf we'll find a the value filled out!

Creating Forms

🚧 Work in Progress

🚧 Work in Progress

Rendering, Extracting Text, Extracting Images

🚧 Work in Progress

Navigating Unsupported Operations

You can access the raw PdfDocument from pypdfium2 using by calling:

from formalpdf import Document

doc = Document("/path/to/your.pdf")

pdfium_doc = doc.document

You can use this to do lower-level operations that aren't yet supported by formalpdf. For instance, if you want to render the first page of the document (currently an unsupported option):

import formalpdf

doc = formalpdf.open("path/to/document.pdf")

pdfium_doc = doc.document
bmp = pdfium_doc[0].render(scale=scale)
pil = bmp.to_pil()

Testing

uv run pytest

There are a large number of test PDFs found in tests/data.

Roadmap

  • create PyPI package
  • finish widget extraction
  • widget updating
    • textbox
    • checkbox
    • combobox
  • widget creation
  • tests

Metadata

Release files for formalpdf 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for formalpdf 0.1.6
File Size Uploaded Provenance Actions
formalpdf-0.1.6.tar.gz 2.0 MB Without provenance Details for formalpdf-0.1.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for formalpdf 0.1.6
File Interpreter ABI Platform Actions
formalpdf-0.1.6-py3-none-any.whl Python 3 none any Details for formalpdf-0.1.6-py3-none-any.whl

Total release size: 2.0 MB

Release files / formalpdf-0.1.6.tar.gz

Download URL formalpdf-0.1.6.tar.gz
Size 2.0 MB
Tags Source
SHA-256 checksum
How to use checksums
cd836fcd5d1f3e5ddbafe65f7b0cb0e924fde751ccb843baf20204290c7e803b
BLAKE2b-256 checksum
How to use checksums
501814e7566c94f7e509192c1e6170216036b12f1149243b3788d42e31ae5821
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.16

Release files / formalpdf-0.1.6-py3-none-any.whl

Download URL formalpdf-0.1.6-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c91bbca1091910b5f5e0cd597161cfd5124c4e5c2f80bd994220044999e65f92
BLAKE2b-256 checksum
How to use checksums
fcaa9dd7d5dcf17e297328e6bc9bdaf726e0dd2da74d4a2193d75cbada923477
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.16

Security for formalpdf 0.1.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page