Skip to main content

Native HTML-to-PDF engine (no Chromium, no headless browser). Python bindings.

Project description

pdfox (Python)

Native HTML-to-PDF rendering for Python — no Chromium, no headless browser, no external binary. A thin PyO3 wrapper over the Rust pdfox-core engine.

Install

pip install pdfox

Wheels are abi3 (abi3-py38), so a single wheel per platform works on CPython 3.8 and newer.

Usage

import pdfox

# Simplest: HTML string in, PDF bytes out.
pdf: bytes = pdfox.render_html("<h1>Hello</h1>")

# Resolve relative <img>/<link> paths against a directory.
pdf = pdfox.render_html(html, base_dir="./assets")

# Full control — returns an object with .pdf and .diagnostics.
result = pdfox.render(
    html,
    base_dir="./assets",
    allow_remote=True,
    deny_list=["internal.corp"],
    pdf_a=True,
    template_vars={"customer": "Acme Inc."},
)
result.pdf            # bytes
result.diagnostics    # list[Diagnostic]
result.has_errors()   # bool

# Convenience: write straight to a file.
pdfox.render_to_file(html, "out.pdf", base_dir="./assets")

Diagnostics

render() never raises for a missing asset or an unsupported CSS feature — it degrades gracefully and records a Diagnostic:

for d in result.diagnostics:
    print(d.severity, d.kind, d.url, "—", d.reason)

kind{"image", "font", "stylesheet", "css_feature"}; severity{"warning", "error"}.

Genuinely broken input raises a pdfox.PdfoxError subclass (ParseError, LayoutError, EmissionError, FontError, ImageError, IoError).

Concurrency

render() and render_html() release the GIL while rendering (the work is pure-Rust and CPU-bound, ~70 ms for a typical page), so they parallelise across threads. In async frameworks, call them from a thread pool:

pdf = await loop.run_in_executor(None, pdfox.render_html, html)

Develop

# From bindings/python/
pip install maturin pytest
maturin develop            # builds the extension into the active venv
pytest                     # runs tests/

On a just-released CPython where the pinned PyO3 has no version table yet, set PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 before building.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

pdfox-0.1.0-cp38-abi3-win_amd64.whl (8.1 MB view details)

Uploaded CPython 3.8+Windows x86-64

pdfox-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.8 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

pdfox-0.1.0-cp38-abi3-macosx_11_0_arm64.whl (8.4 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

Details for the file pdfox-0.1.0-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: pdfox-0.1.0-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 8.1 MB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pdfox-0.1.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a07df67a75faa0143dfff688f841ab12147414d9d0f1436607c3bfca5da77808
MD5 0850d3043fc88adbd9e9bd8efe24ec4e
BLAKE2b-256 09e9f712a478f94c9ececd33bd63e6fb28fe4f6b98ddaab66f7bae32c2c6c0a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pdfox-0.1.0-cp38-abi3-win_amd64.whl:

Publisher: python.yml on sauravrao637/pdfox

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

File details

Details for the file pdfox-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pdfox-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8b97735bdab4ff51aa5ba9d13460854cdcf6f37373d7e6040f3f666709aa899a
MD5 d392d6f0a167ff0465d21bd98f430061
BLAKE2b-256 0c43b9434f1c14143702fc2e17abb4ca230b38ff55797974ba21ad009120fd50

See more details on using hashes here.

Provenance

The following attestation bundles were made for pdfox-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python.yml on sauravrao637/pdfox

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

File details

Details for the file pdfox-0.1.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: pdfox-0.1.0-cp38-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 8.4 MB
  • Tags: CPython 3.8+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pdfox-0.1.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d3a12e20ede4d1648c6d774b4d5fb3a5ead4624b90aa24f8df6cef5c1f73b269
MD5 0285ca9969957c965c8be64d318f8ef0
BLAKE2b-256 4467b042690567d908684bfd3beb63316b057da7fc12173199a479c72f02908e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pdfox-0.1.0-cp38-abi3-macosx_11_0_arm64.whl:

Publisher: python.yml on sauravrao637/pdfox

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