Skip to main content

pdf_engine/
lib.rs

1#![warn(missing_docs)]
2//! Unified PDF rendering engine.
3//!
4//! `pdf-engine` is the main public-facing API for reading and rendering PDF
5//! documents. It wraps the lower-level `pdf-syntax` / `pdf-interpret` /
6//! `pdf-render` stack and exposes a single [`PdfDocument`] handle for all
7//! common operations: page rendering, text extraction, thumbnails, metadata,
8//! bookmarks, and full-text search.
9//!
10//! # Quick Start
11//!
12//! ```no_run
13//! use std::sync::Arc;
14//! use pdf_engine::{PdfDocument, RenderOptions};
15//!
16//! // Load from bytes (accepts Arc<Vec<u8>>, Vec<u8>, or any Into<PdfData>).
17//! let data = Arc::new(std::fs::read("invoice.pdf").unwrap());
18//! let doc = PdfDocument::open(data).unwrap();
19//!
20//! println!("{} pages — {:?}", doc.page_count(), doc.info().title);
21//!
22//! // Render page 0 at 150 DPI → raw RGBA pixel data.
23//! let opts = RenderOptions { dpi: 150.0, ..Default::default() };
24//! let rendered = doc.render_page(0, &opts).unwrap();
25//! println!("{}×{} px", rendered.width, rendered.height);
26//!
27//! // Plain-text extraction.
28//! let text = doc.extract_text(0).unwrap();
29//! println!("{text}");
30//!
31//! // Structured text with per-span positions.
32//! for block in doc.extract_text_blocks(0).unwrap() {
33//!     for span in &block.spans {
34//!         println!("  [{:.0}, {:.0}] {}", span.x, span.y, span.text);
35//!     }
36//! }
37//!
38//! // Full-text search — returns 0-based page indices.
39//! let hits = doc.search_text("total");
40//! println!("'total' found on {} page(s)", hits.len());
41//! ```
42//!
43//! # Key Types
44//!
45//! | Type | Description |
46//! |---|---|
47//! | [`BatchConfig`] / [`BatchResult`] | Worker-pool processing for many PDFs |
48//! | [`PdfDocument`] | Main document handle |
49//! | [`RenderConfig`] / [`RenderOptions`] | DPI, color mode, background colour, optional forced width/height |
50//! | [`RenderedPage`] | RGBA or CMYK pixel data (row-major, 4 bytes per pixel) |
51//! | [`PageGeometry`] | MediaBox, CropBox, TrimBox, BleedBox, rotation |
52//! | [`PageBox`] | A rectangle in PDF user-space points |
53//! | [`DocumentInfo`] | Title, author, subject, creator, producer |
54//! | [`TextBlock`] / [`TextSpan`] | Structured text with position and font size |
55//! | [`BookmarkItem`] | Outline node — title, target page, nested children |
56//! | [`ThumbnailOptions`] | Max-dimension constraint for thumbnail rendering |
57
58// Copyright (c) 2026 Innovation Trigger B.V.
59//
60// PDFluent is available under two licences, at your option: the GNU AGPLv3, or
61// the PDFluent Commercial Licence. See the LICENSE file in this repository --
62// that file travels with the copy you received, which a URL does not.
63
64pub mod api;
65/// Public engine error type and stable error-code mapping. See
66/// [`api_error::PdfEngineError`].
67pub mod api_error;
68pub mod batch;
69/// Visual-to-logical reordering of a line of extracted text (UAX #9 L2).
70/// Internal: extraction reorders, nothing outside it needs to.
71mod bidi;
72pub mod color;
73pub mod document;
74pub mod error;
75pub mod geometry;
76/// Typographic ligatures fold to the letters they stand for. Internal: the
77/// option that turns it off rides on the extraction device.
78mod ligatures;
79pub mod limits;
80pub mod ocr;
81pub mod render;
82pub mod text;
83pub mod text_info;
84pub mod thumbnail;
85#[cfg(feature = "xfa")]
86pub mod xfa;
87
88pub use batch::{process_batch, BatchConfig, BatchResult, ErrorStrategy, PdfBatch};
89pub use color::preserve_device_cmyk;
90pub use document::{join_page_texts, BookmarkItem, DocumentInfo, PdfDocument};
91pub use error::{EngineError, Result};
92pub use geometry::{PageBox, PageGeometry, PageRotation};
93pub use limits::{LimitError, ProcessingLimits};
94pub use ocr::{OcrBackend, OcrError, OcrResult, OcrWord};
95pub use render::{
96    ColorMode, PixelFormat, RasterQuality, RenderConfig, RenderOptions, RenderedPage,
97};
98pub use text::{
99    BoundsSource, FontMetrics, GeometryMode, TextBlock, TextExtractionDevice, TextSpan, WidthSource,
100};
101pub use text_info::TextSpanInfo;
102pub use thumbnail::ThumbnailOptions;
103
104#[cfg(not(target_arch = "wasm32"))]
105pub use ocr::best_available_backend;
106#[cfg(all(feature = "ocr", not(target_arch = "wasm32")))]
107pub use ocr::ocr_page_default;
108#[cfg(feature = "ocr-aws")]
109pub use ocr::AwsTextractBackend;
110#[cfg(feature = "ocr-azure")]
111pub use ocr::AzureDocIntelBackend;
112#[cfg(feature = "ocr-google")]
113pub use ocr::GoogleVisionBackend;
114#[cfg(feature = "ocr-mistral")]
115pub use ocr::MistralOcrBackend;
116#[cfg(feature = "ocr")]
117pub use ocr::OcrsBackend;
118#[cfg(feature = "ocr-onnx")]
119pub use ocr::PaddleOnnxBackend;