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.1.0-py3-none-win_amd64.whl (1.5 MB view details)

Uploaded Python 3Windows x86-64

rustpdf-0.1.0-py3-none-manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

rustpdf-0.1.0-py3-none-manylinux_2_28_aarch64.whl (1.6 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

rustpdf-0.1.0-py3-none-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: rustpdf-0.1.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 1.5 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.1.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 8228ccf8c1c099d4551b3a216b15b5b4ee28493d9355dc46158b68306ecd54c8
MD5 4b22c12756f5b307dd48f15a8df9a678
BLAKE2b-256 0599be4e5b78156d3efb9fde1c280e140eefd545ab4557ae0bcad7c095114e08

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustpdf-0.1.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.1.0-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for rustpdf-0.1.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ed93a8c4a167cb465d27ad86d19fa67c2dd7bed159a2acbf51f5ebadea05d0bf
MD5 2eee87f1079fd632fddb302a0cf1c8c3
BLAKE2b-256 131f275ed3c980056cb742693ca5eb6dc0ee8ba0a5efc7a13a635c536a017859

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustpdf-0.1.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.1.0-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for rustpdf-0.1.0-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 5f5e669dc9d90359d9e632c84e30cb7609efa91b08a3a71b0d56f5907fc20cb8
MD5 1139471900b64f2f01aaae6bb6bd9e90
BLAKE2b-256 afdfdb45650ec30d316734a30c6a1b4c7220ac5c642a57d372fa822a937c58eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustpdf-0.1.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.1.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rustpdf-0.1.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0a3ee5589f794d80b6a3bdd7c8a3064a2422a49f0ab215c3b8182c3b1a94c440
MD5 584b416c30248e06cf03d8b9dc339beb
BLAKE2b-256 11f82983d7e1f7b91cacbfb6cfdeb408211a17623e6b9b73dc1cf8f49a1bf7cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for rustpdf-0.1.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