Skip to main content

Orchestrate end-to-end reproduction of fillable PDF forms as self-contained Typst packages.

Project description

formalizer

Convert a fillable PDF into a self-contained Typst package that anyone can edit and compile to a near-perfect replica.

Maintained by TtQ.

How it works

  1. Extract — PyMuPDF reads the PDF and outputs FIELDS.json (field schema) and pageN.svg background images.
  2. Codegen — The orchestrator writes a Typst package with a typed form() function and a pre-filled example.typ.
  3. Fill — Edit example.typ, replace the dummy values with real ones, compile with typst compile.
<out>/
  typst.toml      # package manifest
  lib.typ         # rendering engine
  FIELDS.json     # extracted field schema
  page1.svg       # vector page backgrounds
  form.typ        # generated API wrapper (do not edit)
  example.typ     # your starting point — edit this

Requirements

  • Python ≥ 3.10
  • typst CLI (for compiling the output package)

Installation

pip install formalizer
# or
uv add formalizer

Usage

CLI

# Generate a package (name defaults to --out basename)
formalizer --pdf form.pdf --out ./my-form

# Override the package name
formalizer --pdf form.pdf --out ./my-form --name custom-name

# Overwrite an existing output directory
formalizer --pdf form.pdf --out ./my-form -f

After generation the CLI auto-compiles example.typexample.pdf so you can immediately preview the result.

Python API

from formalizer import generate

# Minimal — name defaults to the out directory basename
generate(pdf="form.pdf", out="./my-form")

# With options
generate(pdf="form.pdf", out="./my-form", name="custom-name", force=True)

Filling the form

Edit the generated example.typ and pass real values to form():

#import "form.typ": form

#form(
  first_name:  "Jane Smith",
  agree_terms: true,
  gender:      "F",
)

Then compile:

typst compile example.typ filled-form.pdf

Development

# Install in editable mode
pip install -e .

# Run tests
pip install pytest
pytest tests/ -v

Tests that invoke the typst CLI (test_cli, test_codegen_compiles) are skipped automatically if typst is not on PATH.

License

Apache 2.0

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

formalizer-0.2.2.tar.gz (351.5 kB view details)

Uploaded Source

Built Distribution

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

formalizer-0.2.2-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file formalizer-0.2.2.tar.gz.

File metadata

  • Download URL: formalizer-0.2.2.tar.gz
  • Upload date:
  • Size: 351.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for formalizer-0.2.2.tar.gz
Algorithm Hash digest
SHA256 3d0d3fa4bb270b0ccbf0124fab54d67d06245137f79c0f4d760a3f3a56f26250
MD5 eba50ec68d5092c9ea5beb3c93518213
BLAKE2b-256 a1dfcfb9abfc2acfeb6406747b9fafe1c1e9e47c92f1dc3f6a4f5157cb98730e

See more details on using hashes here.

Provenance

The following attestation bundles were made for formalizer-0.2.2.tar.gz:

Publisher: publish.yml on nibsbin/formalizer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file formalizer-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: formalizer-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for formalizer-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 953209a8c917c68a9dda44d03aeaa641d8678eeacfcb87b7ff8c6e411d14d44c
MD5 212991c862071fec6edb1777a7f82a0c
BLAKE2b-256 b732a90f974ea7f8327edc36764ccb69b1d1480e54e451d255f36d9221ddfd68

See more details on using hashes here.

Provenance

The following attestation bundles were made for formalizer-0.2.2-py3-none-any.whl:

Publisher: publish.yml on nibsbin/formalizer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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