Skip to main content

Generate, manipulate, sign and validate PDFs — Python binding for the rust-pdf core

Project description

rustpdf (Python binding)

Idiomatic Python over the rust-pdf C ABI (libpdf_ffi). It mirrors the full product surface: vector graphics, embedded/subsetted fonts and text, wrapping paragraphs, images, PDF/A (levels 1b–3a), tagged/accessible output, embedded file attachments, AcroForm fields, manipulation (merge/split/rotate/optimize/incremental update), text extraction, encryption (RC4 / AES-128 / AES-256) and digital signatures (PKCS#7 / PAdES).

Two layers, per the project's porting strategy:

  • a raw ctypes surface bound 1:1 against include/pdf.h;
  • Document / EditableDoc wrappers that hide opaque handles, raise PdfError on non-zero status codes, and act as context managers.

Install

pip install rustpdf

Platform wheels (macOS arm64, manylinux_2_28 x86_64/aarch64, Windows x64) bundle the native libpdf_ffi library — no Rust toolchain needed to install. Basic PDF generation is free; corporate features (PDF/A, accessibility, encryption, signatures) unlock with a license token via the RUSTPDF_LICENSE env var. See https://rustpdf.dev.

Loading the native library

The wrapper finds libpdf_ffi in this order:

  1. $RUSTPDF_LIB (explicit path);
  2. bundled next to rustpdf/__init__.py (installed wheel);
  3. the build tree (target/debug then target/release).

Build it from the repo root with cargo build -p pdf-ffi.

Quick start

import rustpdf

# Author an accessible PDF/A-2a document.
with rustpdf.Document() as doc:
    doc.pdfa(rustpdf.PdfaLevel.A2A).set_info(title="Report", author="me")
    f = doc.add_font_file("assets/fonts/Roboto-Regular.ttf")
    doc.add_page()
    doc.show_text(f, 20, 72, 760, "Title", heading_level=1)
    doc.paragraph(f, 12, 72, 720, 450, "A wrapping, justified body…",
                  rustpdf.Align.JUSTIFY)
    data = doc.to_bytes()

print(rustpdf.extract_text(data))

# Manipulate an existing file (non-destructive incremental update).
with rustpdf.EditableDoc.load(data) as ed:
    ed.set_info("Subject", "Edited")
    updated = ed.to_bytes_incremental(data)

# Encrypt (AES-256).
with rustpdf.EditableDoc.load(data) as ed:
    ed.encrypt(owner="owner", method=rustpdf.Encryption.AES256)
    ed.save("secured.pdf")

# Sign (PKCS#7 detached / PAdES).
signed = rustpdf.sign(data, key_der, cert_der, reason="Approved", pades=True)

Testing

cargo build -p pdf-ffi
python3 bindings/python/test_binding.py    # dogfood + full-surface exercise
# or: make python-test

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.

rustpdf-0.2.0-py3-none-win_amd64.whl (1.7 MB view details)

Uploaded Python 3Windows x86-64

rustpdf-0.2.0-py3-none-manylinux_2_28_x86_64.whl (1.9 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

rustpdf-0.2.0-py3-none-manylinux_2_28_aarch64.whl (1.8 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

rustpdf-0.2.0-py3-none-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file rustpdf-0.2.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: rustpdf-0.2.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rustpdf-0.2.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 666f28898f950951a428eada526883bde5c286a36065ffe43181c8faaafe0c3f
MD5 664cb98f37cb506d5a5cfb69afe4b8e8
BLAKE2b-256 ea73000bf05cf33feabb1605b9026df456ae60c7db3dbdaf338d8bb063e62ae5

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustpdf-0.2.0-py3-none-win_amd64.whl:

Publisher: release-python.yml on rustpdf/rustpdf

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

File details

Details for the file rustpdf-0.2.0-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for rustpdf-0.2.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 aff12e1f95b5a97c05e0d70f64c1c4704d5bbcf92802da9fd1826b5bfd982263
MD5 99b1df82d3182dc92fbe048168e5c2e4
BLAKE2b-256 c324073cda35eeb2e84769e7a3e53295fc1854f806b07d81b3ae64a53b6e9475

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustpdf-0.2.0-py3-none-manylinux_2_28_x86_64.whl:

Publisher: release-python.yml on rustpdf/rustpdf

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

File details

Details for the file rustpdf-0.2.0-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for rustpdf-0.2.0-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6dc8d8716c38138b9a768279b6b11dbf253d08f65eb1eb6a7b78e74faf69e963
MD5 93dfa35f038a3576804efbadcb53678b
BLAKE2b-256 e2dcad3971c35a10b7c44a8e9cc43992723d73dd928ee094920bf8dbb58720f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustpdf-0.2.0-py3-none-manylinux_2_28_aarch64.whl:

Publisher: release-python.yml on rustpdf/rustpdf

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

File details

Details for the file rustpdf-0.2.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rustpdf-0.2.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 811561177953bd0f5ed412f1a9adc0af01997f989ca85cd9bc8adc28df98fc9f
MD5 2335682378b428d79e85b6ec1d91e529
BLAKE2b-256 f03163bfe4284ac0fb36af4580f194351cb8a66802849354cd6924a8a8cd7450

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustpdf-0.2.0-py3-none-macosx_11_0_arm64.whl:

Publisher: release-python.yml on rustpdf/rustpdf

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