docuparse
High-performance document extraction library for Rust.
Extracts text and renders pages from PDF documents using the Pdfium engine — the same C++ library used by Google Chrome.
Features
- Native text extraction — extracts text directly from PDF text layers, no OCR required for digitally generated documents
- Page rendering — renders PDF pages to images at configurable DPI with optional annotation rendering and dimension clamping
- Automatic page classification — detects whether a page has a native text layer or is scanned
- PDF validation — magic byte checking, size guards, existence checks
- Document metadata — title, author, page count, file size, PDF version
- Zero intermediate files — everything in memory, no temp file I/O
- Pdfium singleton — initialised once, borrowed across your application
Installation
[]
= "0.0.1"
Docuparse links against Pdfium at runtime. You must provide the Pdfium shared library alongside your binary. Pre-built binaries are available from the pdfium-render releases.
Quick Start
use ;
Page Rendering
use ;
let pdfium = init_pdfium?;
let doc = open?;
let config = builder
.dpi
.with_annotations
.build;
let image = doc.render_page?;
image.save?;
Batch Rendering
let images = doc.render_all_pages?;
for in images.iter.enumerate
Performance
Benchmarked on a representative mixed PDF document (native text layers + scanned pages) on Apple Silicon (M4):
| Metric | Value |
|---|---|
| Text extraction (12 pages) | ~8 ms |
| Per page | ~680 µs |
| Memory RSS | ~25 MB |
| Child processes spawned | 0 |
| Temp file I/O | none |
Performance is dominated by the Pdfium C++ engine. The Rust wrapper contributes negligible overhead — dev and release builds measure identically, confirming zero Rust-level bottleneck.
Error Handling
All public functions return Result<T, PdfError>. Errors are fully typed
via thiserror and compose cleanly
with anyhow or eyre in application code:
use PdfError;
match open
Roadmap
- OCR support via ONNX Runtime (feature flag)
- Image input (JPEG, PNG) alongside PDF
- Async API
License
MIT