djvu-rs
Pure-Rust DjVu decoder. MIT licensed. Written from the DjVu v3 public specification.
Features
- IFF container parser — zero-copy, borrowing slices from input
- JB2 bilevel image decoder — adaptive arithmetic coding (ZP coder) with symbol dictionary
- IW44 wavelet image decoder — planar YCbCr storage, multiple refinement chunks
- BZZ decompressor — ZP arithmetic coding + MTF + BWT (DIRM, NAVM, ANTz chunks)
- Text layer extraction — TXTz/TXTa chunk parsing with zone hierarchy (page/column/region/paragraph/line/word/character)
- Annotation parsing — ANTz/ANTa chunk parsing (hyperlinks, map areas, background color)
- Bookmarks — NAVM table-of-contents parsing
- Multi-page documents — DJVM bundle format with DIRM directory chunk
- Page rendering — composite foreground + background into RGBA output
- Progressive rendering — incremental BG44 wavelet refinement
- Thumbnails — TH44 embedded thumbnail extraction
no_stdcompatible — IFF/BZZ/JB2/IW44/ZP modules work withalloconly (nostd)
Quick start
use Document;
let doc = open?;
println!;
let page = doc.page?;
println!;
let pixmap = page.render?;
// pixmap.data is RGBA bytes (4 bytes per pixel, row-major)
// pixmap.width, pixmap.height are dimensions in pixels
Text extraction
use Document;
let doc = open?;
let page = doc.page?;
if let Some = page.text?
Low-level IFF access
use parse_form;
let data = read?;
let form = parse_form?;
println!;
for chunk in &form.chunks
Feature flags
| Flag | Default | Description |
|---|---|---|
std |
enabled | Enables Document, Page, file I/O, and rendering. Disable for no_std |
Without std, the crate provides IFF parsing, BZZ decompression, JB2/IW44 decoding, text/annotation parsing — all codec primitives that work on byte slices.
Minimum supported Rust version (MSRV)
Rust 1.88 (edition 2024 features: let-chains stabilized in 1.88)
Roadmap
See GitHub milestones for the full roadmap and progress tracking.
Next up: v0.2 — Structural PDF export — proper DjVu → PDF with selectable text, lossless IW44/JB2 embedding, and preserved bookmarks/hyperlinks.
License
MIT. See LICENSE.
Specification
Written from the public DjVu v3 specification:
- https://www.sndjvu.org/spec.html
- https://djvu.sourceforge.net/spec/DjVu3Spec.djvu (the spec is itself a DjVu file)
No code derived from GPL-licensed DjVuLibre or any other GPL source. All algorithms are independent implementations from the spec.