Expand description
Unified PDF rendering engine.
pdf-engine is the main public-facing API for reading and rendering PDF
documents. It wraps the lower-level pdf-syntax / pdf-interpret /
pdf-render stack and exposes a single PdfDocument handle for all
common operations: page rendering, text extraction, thumbnails, metadata,
bookmarks, and full-text search.
§Quick Start
use std::sync::Arc;
use pdf_engine::{PdfDocument, RenderOptions};
// Load from bytes (accepts Arc<Vec<u8>>, Vec<u8>, or any Into<PdfData>).
let data = Arc::new(std::fs::read("invoice.pdf").unwrap());
let doc = PdfDocument::open(data).unwrap();
println!("{} pages — {:?}", doc.page_count(), doc.info().title);
// Render page 0 at 150 DPI → raw RGBA pixel data.
let opts = RenderOptions { dpi: 150.0, ..Default::default() };
let rendered = doc.render_page(0, &opts).unwrap();
println!("{}×{} px", rendered.width, rendered.height);
// Plain-text extraction.
let text = doc.extract_text(0).unwrap();
println!("{text}");
// Structured text with per-span positions.
for block in doc.extract_text_blocks(0).unwrap() {
for span in &block.spans {
println!(" [{:.0}, {:.0}] {}", span.x, span.y, span.text);
}
}
// Full-text search — returns 0-based page indices.
let hits = doc.search_text("total");
println!("'total' found on {} page(s)", hits.len());§Key Types
| Type | Description |
|---|---|
BatchConfig / BatchResult | Worker-pool processing for many PDFs |
PdfDocument | Main document handle |
RenderConfig / RenderOptions | DPI, color mode, background colour, optional forced width/height |
RenderedPage | RGBA or CMYK pixel data (row-major, 4 bytes per pixel) |
PageGeometry | MediaBox, CropBox, TrimBox, BleedBox, rotation |
PageBox | A rectangle in PDF user-space points |
DocumentInfo | Title, author, subject, creator, producer |
TextBlock / TextSpan | Structured text with position and font size |
Block / BlockKind / ExtractOptions | Paragraphs, headings and list items, and which pages of them come back |
Word | One word with its box, page, block and line |
to_markdown / to_json | Those blocks as markdown for a reader, or as JSON for a chunker |
BookmarkItem | Outline node — title, target page, nested children |
ThumbnailOptions | Max-dimension constraint for thumbnail rendering |
Re-exports§
pub use batch::process_batch;pub use batch::process_batch_with_page_progress;pub use batch::BatchConfig;pub use batch::BatchResult;pub use batch::ErrorStrategy;pub use batch::PdfBatch;pub use blocks::Block;pub use blocks::BlockKind;pub use blocks::ClipMargins;pub use blocks::ExtractOptions;pub use blocks::OcrMode;pub use blocks::PageSeparators;pub use blocks::Quality;pub use blocks::TableRenderMode;pub use blocks::TableStrategy;pub use blocks::TatrOptions;pub use color::preserve_device_cmyk;pub use docling::to_docling_json;pub use docling::DoclingPage;pub use document::join_page_texts;pub use document::BookmarkItem;pub use document::DocumentInfo;pub use document::PdfDocument;pub use error::EngineError;pub use error::OptionsError;pub use error::Result;pub use geometry::PageBox;pub use geometry::PageGeometry;pub use geometry::PageRotation;pub use json::to_json;pub use limits::LimitError;pub use limits::ProcessingLimits;pub use markdown::to_markdown;pub use markdown::to_markdown_with_code;pub use markdown::to_markdown_with_options;pub use markdown::MarkdownOptions;pub use ocr::OcrBackend;pub use ocr::OcrError;pub use ocr::OcrResult;pub use ocr::OcrWord;pub use ocr_need::page_needs_ocr;pub use ocr_need::OcrNeed;pub use render::ColorMode;pub use render::PixelFormat;pub use render::RenderConfig;pub use render::RenderOptions;pub use render::RenderedPage;pub use text::BoundsSource;pub use text::FontMetrics;pub use text::GeometryMode;pub use text::LayoutBlock;pub use text::TextBlock;pub use text::TextSpan;pub use text::WidthSource;pub use text_info::TextSpanInfo;pub use thumbnail::ThumbnailOptions;pub use words::to_json_with_words;pub use words::to_words_json_lines;pub use words::Word;pub use ocr::best_available_backend;pub use ocr::ocr_page_default;pub use ocr::AwsTextractBackend;pub use ocr::AzureDocIntelBackend;pub use ocr::GoogleVisionBackend;pub use ocr::MistralOcrBackend;pub use ocr::OcrsBackend;pub use ocr::PaddleOnnxBackend;
Modules§
- api
- The ideal top-level API facade for the PDFluent SDK.
- api_
error - Public engine error type and stable error-code mapping. See
[
api_error::PdfEngineError]. - balanced
- The balanced tier’s page assembly: detector boxes plus our own text (#641).
Off by default, beside
layout. The balanced tier’s page assembly: detector boxes plus our own text, page in, markdown out (#641). - batch
- Batch helpers for processing many PDFs with a bounded worker pool.
- blocks
- Paragraphs and the
blocks::Blockmodel the structured serializers consume (#567). Paragraphs out of the lines a page draws (#567). - color
- Color helpers for render output conversion.
- docling
- The block model as a Docling
DoclingDocument(#629). - document
- Unified document facade — multi-page rendering, text extraction, metadata, bookmarks, and thumbnails.
- error
- Error types for the rendering engine.
- geometry
- Page geometry: boxes (MediaBox, CropBox, TrimBox, BleedBox, ArtBox), rotation, and DPI-based pixel conversions.
- json
- The block model as JSON: every block with its kind, page, box, text, spans and reading-order index, for a caller that chunks the document itself (#572). The block model as JSON, for callers that chunk it themselves (#572).
- layout
- Layout detection on the shared ONNX Runtime layer (#641). Off by default. Layout detection on the shared ONNX Runtime layer (#641).
- limits
- Resource limits for PDF processing.
- markdown
- The block model as markdown: headings, lists, tables and a marker where the page changed (#572). The block model as markdown (#568, #569, #570, #571).
- markdown_
images - Figures in the block model: listing, naming, pixels, and references (#658). Figures in the block model: listing, naming, pixels, and references.
- model
- The model tiers’ shared surface: specs, failures and install paths (#641).
Always compiled; only the session half needs the
ortfeature. The model tiers’ shared surface: specs, failures and install paths (#641). - ocr
- OCR backend trait and implementations.
- ocr_
need - Scan detection: how much OCR a page needs, before any recognizer runs. Scan detection: how much OCR a page needs, before any recognizer runs.
- render
- Page rendering with z-order compositing.
- text
- Text extraction via a custom Device implementation.
- text_
info - Canonical, serializable wire form of an extracted text span.
- thumbnail
- Thumbnail generation options.
- vision
- Optional vision layer: raster plus ONNX runner (#636). Off by default. Optional vision layer: page raster plus ONNX runner (#636).
- words
- Word-level boxes for citations, highlighting and grounding.
- words_
join - The rule that decides whether two adjacent pieces read as one word.
- xfa
- XFA feature surface for
pdf-engine.
Enums§
- Raster
Quality - Rasterization precision / speed trade-off for the vello_cpu pipeline.