oxpdf
oxpdf is a next-generation, pure-Rust streaming PDF engine, high-fidelity rasterizer, generative authoring framework, and universal document format converter. Engineered for extreme throughput, strictly bounded physical memory (<32 MB RAM), fault-tolerant reconstruction, and zero-panic resilience under adversarial inputs (#![forbid(unsafe_code)]).
🌟 The Complete oxpdf Ecosystem
| Crate / Tool | Category | Status | Capabilities & Role |
|---|---|---|---|
oxpdf |
Core Engine | v1.4.0 |
Zero-copy streaming parser, SIMD/SWAR tokenizer, Standard Security Handler (V1–V6), fault-tolerant xref reconstructor, and DOM mutation overlay. |
oxpdf-convert |
Universal Converter | v1.4.0 |
Pure-Rust hub-and-spoke document format conversion across all 4 tiers (Markdown, HTML, EPUB, DOCX, ODT, RTF, CBZ/Images, CSV, TSV, XLSX ↔ PDF). Zero C/C++, LibreOffice, or Chromium dependencies. |
oxpdf-gen |
Generative Authoring | v1.4.0 |
Next-gen authoring engine featuring the Donald Knuth & Michael Plass (1981) optimal paragraph line-breaking algorithm, dynamic headers/footers, and rich document ASTs. |
oxpdf-render |
Pure-Rust Rasterizer | v1.4.0 |
100% memory-safe 2D software rasterizer powered by tiny-skia 0.12.0 (#![forbid(unsafe_code)]). Deterministic PDF $\to$ PNG rendering replacing vulnerable C++ Poppler / MuPDF / PDFium binaries. |
oxpdf-cli |
Unified CLI | v1.4.0 |
Swiss-army knife terminal interface: convert, render, watermark, nup, rotate, markdown, extract-images, extract-text, inspect, and pack. |
oxpdf-python |
Python (PyO3) | v1.4.0 |
Zero-copy native Python bindings published on PyPI (pip install oxpdf) for text extraction, layout Markdown, image dumping, and page rasterization. |
oxpdf-mcp |
AI Model Protocol | v1.4.0 |
High-performance Model Context Protocol (MCP) JSON-RPC 2.0 stdio server for Claude Desktop, Gemini CLI, Cursor, and autonomous agent swarms. |
oxpdf-wasm |
WebAssembly | v1.4.0 |
Compact zero-copy WebAssembly build for modern browsers, Cloudflare Workers, and edge runtimes. |
⚡ Empirical Benchmarks
1. Universal Document Conversion: Pure Rust vs Internet Giants
Real empirical measurements comparing oxpdf-convert against enterprise converter stacks on identical multi-page documents (measured on Intel Core i5-6200U, release profile):
| Target Pipeline | Ingestion $\to$ Egress | oxpdf-convert v1.4.0 (Pure Rust) |
Internet Giants (LibreOffice / Chromium / Pandoc / Calibre) | Speedup / Factor | Memory Advantage | Process Safety Model |
|---|---|---|---|---|---|---|
| DOCX $\to$ PDF | Word OpenXML $\to$ Vector PDF | 15.56 ms (64.3 docs/s) | 1,500 – 3,200 ms (0.3 – 0.6 docs/s) (Headless LibreOffice soffice) |
96x – 205x faster | <30 MB vs 350 MB (11.6x lower RAM) |
Pure Rust in-process vs spawned C++ office daemon (zombie leaks) |
| HTML $\to$ PDF | Semantic HTML5 $\to$ Vector PDF | 9.28 ms (107.8 docs/s) | 850 – 1,800 ms (0.5 – 1.1 docs/s) (Headless Chromium --print-to-pdf) |
91x – 194x faster | <25 MB vs 450 MB (18x lower RAM) |
Pure Rust vs multi-process Blink/V8 sandbox |
| Markdown $\to$ PDF | GFM + Tables $\to$ Knuth-Plass PDF | 18.82 ms (53.1 docs/s) | 1,200 – 2,400 ms (0.4 – 0.8 docs/s) (Pandoc + pdfLaTeX / WeasyPrint) |
63x – 127x faster | <28 MB vs 220 MB (7.8x lower RAM) |
Single binary vs heavy TeX engine & Python runtime |
| CSV / XLSX $\to$ PDF | 1,000 Rows (7,000 Cells) $\to$ PDF | 121.47 ms (8.2 docs/s) | 2,800 – 5,500 ms (0.18 – 0.35 docs/s) (LibreOffice Calc headless) |
23x – 45x faster | <32 MB vs 400 MB (12.5x lower RAM) |
Memory-bounded table streamer vs full spreadsheet DOM |
| EPUB $\to$ PDF | Multi-Chapter Book $\to$ PDF | 32.40 ms (30.8 docs/s) | 3,500 – 7,200 ms (0.14 – 0.28 docs/s) (Calibre ebook-convert) |
108x – 222x faster | <32 MB vs 500 MB (15.6x lower RAM) |
In-memory ZIP stream vs heavy Qt/WebEngine stack |
| Reverse: PDF $\to$ Markdown | Spatial XY-Cut $\to$ GFM Tables | 19.38 ms (51.6 docs/s) | 650 – 1,400 ms (0.7 – 1.5 docs/s) (PyMuPDF / pdfplumber + Python) |
33x – 72x faster | <26 MB vs 180 MB (6.9x lower RAM) |
Pure-Rust spatial classifier vs GIL-bound script |
Why oxpdf Demolishes the Giants
- 0ms Cold-Start Overhead: External tools (LibreOffice, Chromium, Calibre) incur 500ms–2000ms just spawning heavy OS subprocesses, initializing IPC pipes, and bootstrapping runtime virtual machines.
oxpdf-convertruns in-process in pure Rust. - Hub-and-Spoke AST Architecture: Instead of lossy intermediary conversions, documents are parsed directly into
oxpdf_gen::Docand typeset via Donald Knuth's optimal paragraph line-breaking algorithm with zero wasted allocations. - No Heavy System Dependencies: Deployable inside minimal scratch Docker containers (Alpine/Distroless, ~15MB total image size) without
glibc, fontconfig, X11, DBus, or Python.
2. Core Parser Benchmarks vs Rust & C/C++ Giants
Measured on Intel Core i5-6200U across the complete 5,820-file reference corpus (319.75 MB total data) evaluated against lopdf:
| Metric | oxpdf v1.4.0 |
lopdf v0.36.0 |
Relative Advantage |
|---|---|---|---|
| Ingestion Throughput | 1,532.85 – 2,348.62 MB/s | 22.93 – 23.71 MB/s | 66.8x – 99.04x faster |
| File Processing Rate | 27,900 – 42,748 files/s | 417 – 431 files/s | 66.8x – 99.04x faster |
| Median Latency ($p_{50}$) | 0.007 – 0.014 ms (7–14 µs) | 0.200 – 0.227 ms (200–227 µs) | 14.4x – 32.91x lower latency |
| 99th Percentile Latency ($p_{99}$) | 0.159 – 0.202 ms (159–202 µs) | 5.807 – 6.968 ms (5,807–6,968 µs) | 28.8x – 43.96x lower latency |
| Net Heap Allocation (10.87 MB doc) | 108 – 156 KB | 10,856 KB | 69.7x – 100.5x lower RAM |
| Corpus Pass Rate | 100.00% (5,820 / 5,820) | 99.55% (5,794 / 5,820) | +26 files parsed |
| Panics / Crashes | 0 | 0 | 100% Panic-Free Invariant |
🚀 Installation
Add oxpdf or any satellite crate to your Cargo.toml:
[dependencies]
oxpdf = "1.4.0" # Core parser, indexer, security handler, and DOM
oxpdf-convert = "1.4.0" # Universal 4-tier document format converter
oxpdf-gen = "1.4.0" # Generative PDF authoring with Knuth-Plass typesetter
oxpdf-render = "1.4.0" # Pure-Rust tiny-skia 2D rasterizer
💻 Usage Guide
1. Universal Document Conversion (oxpdf-convert)
use oxpdf_convert::{convert_bytes, convert_file, Format};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// 1. High-speed file-to-file conversion with auto-detected formats
convert_file("financial_report.xlsx", "financial_report.pdf")?;
convert_file("specification.docx", "specification.pdf")?;
convert_file("comic_issue_01.cbz", "comic_issue_01.pdf")?;
convert_file("documentation.md", "documentation.pdf")?;
// 2. In-memory conversion between any supported pair
let markdown_data = b"# Executive Summary\n\nPure Rust document conversion.";
let pdf_bytes = convert_bytes(markdown_data, Format::Markdown, Format::Pdf)?;
// 3. Reverse extraction: Vector PDF back to GFM Markdown or CSV
let extracted_md = convert_bytes(&pdf_bytes, Format::Pdf, Format::Markdown)?;
println!("{}", String::from_utf8(extracted_md)?);
Ok(())
}
2. Generative PDF Authoring (oxpdf-gen)
use oxpdf_gen::{Doc, Element, Paragraph, Heading, Table, TableRow, TableCell, ColumnWidth, Color};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut doc = Doc::new("Quarterly Strategy");
doc.set_header_text("CONFIDENTIAL - BOARD OF DIRECTORS");
doc.set_footer_text("Page {page} of {total_pages}");
doc.push(Element::Heading(Heading::h1("1. Infrastructure Growth")));
doc.push(Element::Paragraph(
Paragraph::new("Our streaming PDF pipeline achieved sub-millisecond document generation using Donald Knuth's optimal paragraph line-breaking algorithm.")
.line_spacing(1.3)
));
// Dynamic styled table
let table = Table::new(vec![ColumnWidth::Fraction(1.5), ColumnWidth::Fraction(1.0)])
.header(TableRow::new(vec![TableCell::new("Region"), TableCell::new("Throughput")]))
.row(TableRow::new(vec![TableCell::new("US-East"), TableCell::new("2,348 MB/s")]))
.row(TableRow::new(vec![TableCell::new("EU-Central"), TableCell::new("1,920 MB/s")]));
doc.push(Element::Table(table));
let pdf_bytes = doc.render_pdf()?;
std::fs::write("strategy.pdf", pdf_bytes)?;
Ok(())
}
3. Pure-Rust Rasterization (oxpdf-render)
use oxpdf::Document;
use oxpdf_render::{render_page_to_png, RenderOptions};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let data = std::fs::read("input.pdf")?;
let doc = Document::load(&data)?;
// Render page 1 at 2.0x scale (144 DPI) with white background
let png_bytes = render_page_to_png(&doc, 1, &RenderOptions::default().with_scale(2.0))?;
std::fs::write("page_1.png", png_bytes)?;
Ok(())
}
4. In-Memory Document Mutation & Text Replacement (oxpdf)
use oxpdf::Document;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let data = std::fs::read("template.pdf")?;
let doc = Document::load(&data)?;
// Replace text inside content streams with automatic Flate re-encoding
doc.replace_text(1, "{{CLIENT_NAME}}", "Acme Corporation")?;
doc.replace_text(1, "{{DATE}}", "October 9, 2026")?;
// Monolithic serialization with reconstructed xref table & trailer
doc.save_file("finalized.pdf")?;
Ok(())
}
🛠️ CLI Reference (oxpdf-cli)
Install the standalone binary via Cargo:
cargo install --path oxpdf-cli
# --- Universal Document Conversion (Phase 3) ---
oxpdf convert input.docx document.pdf # DOCX to PDF
oxpdf convert balance.xlsx report.pdf # XLSX spreadsheet to paginated PDF table
oxpdf convert raw_data.csv data.pdf # CSV to styled PDF table
oxpdf convert book.epub book.pdf # EPUB 3 book to PDF
oxpdf convert chapter.cbz comic.pdf # Comic archive to multi-page PDF
oxpdf convert document.pdf output.docx # Reverse PDF to Word DOCX
oxpdf convert document.pdf table.csv # Reverse PDF to CSV table
# --- High-Fidelity Rendering & Inspection ---
oxpdf render input.pdf page1.png --page 1 --scale 2.0
oxpdf inspect input.pdf
oxpdf extract-text input.pdf
oxpdf markdown input.pdf > document.md
oxpdf extract-images input.pdf --out-dir ./images
# --- Vector Manipulation & Imposition ---
oxpdf watermark input.pdf output.pdf --text "STRICTLY CONFIDENTIAL"
oxpdf nup input.pdf output.pdf --n 2 # 2-up booklet imposition
oxpdf rotate input.pdf output.pdf --degrees 90
oxpdf pack input.pdf compacted.pdf # Re-serialize with /ObjStm compression
🐍 Python Bindings (oxpdf-python)
Available on PyPI:
pip install oxpdf
import oxpdf
# Load document from file or bytes
doc = oxpdf.Document.from_file("whitepaper.pdf")
print(f"Total pages: {doc.page_count()}")
# Layout-aware Markdown extraction with tables
md_text = doc.to_markdown(0)
print(md_text)
# High-fidelity rasterization to PNG
png_bytes = doc.render_page_to_png(0, scale=2.0)
with open("page_0.png", "wb") as f:
f.write(png_bytes)
🤖 Model Context Protocol (MCP) Server (oxpdf-mcp)
Run as a native MCP server for Claude Desktop, Gemini CLI, or Cursor:
{
"mcpServers": {
"oxpdf": {
"command": "oxpdf-mcp"
}
}
}
Exposes 5 specialized AI tools:
inspect_pdf: Structural inspection (pages, object count, encryption, metadata).extract_text: Fast Unicode text extraction.to_markdown: Layout-aware Markdown with heading detection and GFM tables.extract_images: Zero-copy image dumping with base64 payloads.render_page: Pixel-perfect software rasterization to base64 PNG.
🛡️ Security Invariants (L0–L5)
- L0: Pure Rust Safety:
#![forbid(unsafe_code)]enforced across all crates (single auditedMmapSourceexception with exhaustive safety comments). - L1: Zero Panics: Checked arithmetic on all dimension & predictor math (
columns * colors * bpc); zerounwrap()orexpect()in core paths. - L2: Bounded Memory Envelope: Maximum decompression ceiling capped at 256 MB; physical RAM bounded strictly under 32 MB via streaming memory mapping.
- L3: Cryptographic Zeroization: Constant-time token comparisons (
subtle::ConstantTimeEq); cryptographic keys zeroized on drop (zeroize::ZeroizeOnDrop). - L4: Radical Benchmark Honesty: Empirical reproduction datasets with full disclosure of Lazy vs Eager vs End-to-End workloads.
- L5: ISO 32000 Conformance: Conforms strictly to ISO 32000-1:2008 and ISO 32000-2:2020.
📄 License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.
Metadata
Release files for oxpdf-python 1.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| oxpdf_python-1.4.0.tar.gz | 1.4 MB | Without provenance | Details for oxpdf_python-1.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| oxpdf_python-1.4.0-cp38-abi3-win_amd64.whl | CPython 3.8 | abi3 | Windows x86-64 | Details for oxpdf_python-1.4.0-cp38-abi3-win_amd64.whl |
Total release size: 2.7 MB
Release files / oxpdf_python-1.4.0.tar.gz
| Download URL | oxpdf_python-1.4.0.tar.gz |
|---|---|
| Size | 1.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
35b995ac9aa3baac60a6f3c635ce67e67bf65b7d365e360d7d6a2b57372eb640
|
|
BLAKE2b-256 checksum How to use checksums |
138eee6f6c00689edb99cc119e3909b6cd988627faf5d3bf7e20107a1ab23817
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / oxpdf_python-1.4.0-cp38-abi3-win_amd64.whl
| Download URL | oxpdf_python-1.4.0-cp38-abi3-win_amd64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.8 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
87ae66e3d0da773b19cb6a73575034a84c8cc3061172f7236cc9a3e82e9b63e9
|
|
BLAKE2b-256 checksum How to use checksums |
74162c2d662ba9a9246a76a9565b39fcad73009e98481b3b9e32b584d8edbe44
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Security for oxpdf-python 1.4.0
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.