easypdf-reader
PDF reading layer: parsing, text extraction, page manipulation (merge/split/rotate/reorder/watermark), with three adaptive read strategies.
Role
easypdf-reader handles all PDF input operations in the easypdf-rust workspace. Built on the lopdf backend, it provides text extraction, metadata reading, page manipulation (merge, split, rotate, reorder, watermark, layer), and PDF/A validation. It automatically selects the optimal read strategy based on file size to balance speed for small files against memory efficiency for large ones.
Core Capabilities
- Three read strategies (
Full/Lazy/Streaming) -- auto-selected by file size: 0-5 MB = Full, 5-100 MB = Lazy, >100 MB = Streaming (crates/easypdf-reader/src/strategy.rs:56-68) - Text extraction (
extract_text()) -- plain text from PDF, with CMap/ToUnicode support for CJK fonts (crates/easypdf-reader/src/reader/extract.rs) - Page manipulation (
PdfManipulator) -- merge, split, rotate, reorder, extract pages, add text watermark, add optional content groups (layers) (crates/easypdf-reader/src/manipulate.rs) - PDF repair (
open_with_repair()) -- auto-detect and fix corrupted PDF files (crates/easypdf-core/src/io/repair.rs) - Resource guards -- decompression bomb and element explosion protection via
ResourceLimits(crates/easypdf-core/src/io/guards.rs) - Streaming scanner (
StreamScanner) -- byte-stream scanning without building a fullDocumentobject for very large files (crates/easypdf-reader/src/streaming/) - PDF/A validation (
validate_pdfa()) -- check PDF/A-1b compliance (crates/easypdf-reader/src/manipulate.rs:260) - Benchmark suite -- reader session benchmarks (
crates/easypdf-reader/benches/reader_session.rs)
Dependencies
Internal
| Crate | Purpose |
|---|---|
easypdf-core |
Core types (PdfInput, ResourceLimits, PageRange, error types, IO guards) |
External
| Crate | Version | Purpose |
|---|---|---|
lopdf |
0.44.0 | PDF parsing engine |
flate2 |
1.1.9 | Stream decompression (Streaming strategy) |
Main API
PdfReader
use ;
// Auto strategy (selected by file size)
let reader = open?;
let text = reader.extract_text?;
// Specify strategy
let reader = open_with_strategy?;
let text = reader.pages.extract_text?;
// From memory bytes
let reader = from_bytes?;
// With auto-repair
let reader = open_with_repair?;
// With custom resource limits
let reader = open_with_limits?;
ReadStrategy
use ReadStrategy;
// Auto-select by file size
let strategy = auto; // 50 MB -> Lazy
// Manual selection
let s = Full; // <5 MB, full object tree
let s = Lazy; // 5-100 MB, lazy page loading
let s = Streaming; // >100 MB, byte-stream scan
PdfManipulator
use PdfManipulator;
// Merge multiple PDFs
merge_files?;
// Open and manipulate
let mut m = open?;
m.rotate_page?;
m.reorder_pages?;
m.extract_pages?;
m.add_text_watermark?;
m.add_layer?;
m.validate_pdfa?;
Known Limitations
ReadStrategy::Streamingdoes not build a complete object tree -- precision is lower than Full/Lazy, especially for CJK text boundaries (crates/easypdf-reader/src/strategy.rs:47-51)- Streaming mode skips cross-reference parsing and font encoding (CMap/ToUnicode) for speed
License
Apache-2.0
Project: https://github.com/easy-4-rust/easypdf-rust crates.io: https://crates.io/crates/easypdf-reader docs.rs: https://docs.rs/easypdf-reader