DjVu
| Full name | DjVu ("déjà vu") |
|---|---|
| Extensions | .djvu, .djv |
| MIME type | image/vnd.djvu (also image/x-djvu) |
| Type | document format for scanned pages, layered (mixed raster content) compression |
| Starts with | 41 54 26 54 46 4F 52 4D (AT&TFORM) |
| Specification | DjVu Reference, version 3 (transcription of the Lizardtech 2005 spec) |
| Reference implementation | DjVuLibre |
| Maintained by | no active standards body; DjVuLibre is the de facto reference |
| License | open specification, royalty-free; DjVuLibre is GPL |
DjVu stores scanned pages: books, journals, manuals, maps and old documents. It splits each page into layers and compresses each with a method suited to it: text and line art as a sharp black-and-white mask, and paper texture, photos and colors as a low-resolution wavelet image. A scanned 300 dpi book page often takes 20-60 KB, several times smaller than the same page as a JPEG in a PDF.
A DjVu file can have a hidden text layer from OCR (so you can search and copy text), hyperlinks, a table of contents and thumbnails. Most digital libraries of old books moved to PDF, but large DjVu collections remain, especially of scanned science and math books.
When to use DjVu#
- Use for archiving scanned books and documents when file size matters: DjVu is usually 3-10 times smaller than a PDF made of JPEG pages at similar quality.
- Use for black-and-white scans of text: the JB2 encoder stores a repeated letter shape once and reuses it.
- Avoid for documents created on a computer (text, vector graphics, fonts): DjVu has no fonts or vector drawing, every page is an image. Use PDF.
- Avoid when you share files with people who use default OS apps: Windows and macOS don’t open DjVu without extra software. PDF with JBIG2 compression gets close to DjVu sizes and opens everywhere.
File structure#
DjVu uses the EA IFF 85 container, the same chunk structure as AIFF and the old Amiga formats. The file starts with the 4-byte magic AT&T, followed by one FORM chunk. Each chunk has a 4-character ID, a 4-byte big-endian length and the data. Chunk data is padded to an even length.
41 54 26 54 "AT&T" magic
46 4F 52 4D "FORM"
00 00 2E 1A length of the FORM
44 4A 56 55 "DJVU" (single page)
49 4E 46 4F "INFO" chunk
00 00 00 0A length: 10
08 9A 03 C7 width 2202, height 967 (big-endian)
1A 00 version: minor 26, major 0
2C 01 300 dpi (little-endian!)
16 gamma 2.2 (x10)
01 flags: rotation 0
53 6A 62 7A ... "Sjbz" chunk: JB2 mask
... BG44, FG44, TXTz, ANTz chunks
Document types#
| FORM type | Contents |
|---|---|
FORM:DJVU |
one page. A single-page file is just this form |
FORM:DJVM |
multi-page document. Starts with a DIRM directory chunk, then optional NAVM (outline), then the page forms |
FORM:DJVI |
shared data used by several pages (shape dictionary, annotations), referenced with INCL |
FORM:THUM |
page thumbnails (TH44 chunks) |
A multi-page document is either bundled (one .djvu file with all pages inside) or indirect (an index file whose DIRM lists separate per-page files). Indirect documents let a web server send one page at a time; bundled files are easier to handle.
Page chunks#
| Chunk | Contents |
|---|---|
INFO |
page width and height in pixels, version, resolution in dpi, gamma, rotation. Must be first |
Sjbz |
foreground mask: bitonal image (text, lines) compressed with JB2 |
Smmr |
alternative mask compressed with fax G4 (MMR) |
Djbz |
shared JB2 shape dictionary (usually in a FORM:DJVI shared by many pages) |
INCL |
ID of a shared FORM:DJVI component used by this page |
BG44 |
background image compressed with IW44 wavelets, often in several chunks that refine the image progressively |
FG44 |
foreground colors as an IW44 image |
FGbz |
foreground colors as a palette, one color per JB2 shape |
BGjp, FGjp |
background or foreground stored as JPEG (rare) |
TXTz |
hidden text and its layout: page, column, region, paragraph, line, word and character zones with coordinates. BZZ-compressed (TXTa is the uncompressed form) |
ANTz |
annotations: hyperlinks, highlighted areas, background color, initial zoom and metadata. BZZ-compressed (ANTa uncompressed) |
How a page is rendered#
The page image is a combination of 3 layers, the mixed raster content (MRC) model:
- Background (
BG44): paper texture and pictures, usually at 1/3 of the full resolution (100 dpi for a 300 dpi scan). - Mask (
Sjbz): a full-resolution black-and-white image that says which pixels belong to the foreground. - Foreground colors (
FG44orFGbz): the color of the masked pixels, usually very low resolution.
A pure black-and-white page has only INFO and Sjbz. A photo page has only BG44.
The compression methods are specific to DjVu:
- JB2: a bitonal image coder similar to JBIG2. It finds shapes (letters), stores each distinct shape once and refers to it at every position. In lossy mode, shapes that look almost the same are merged.
- IW44: a wavelet coder for color and grayscale images. Data arrives in slices, so a viewer can show a blurry page first and sharpen it as more chunks arrive.
- BZZ: a general-purpose compressor (Burrows-Wheeler transform with an adaptive arithmetic coder) used for text, annotations, the directory and the outline.
- ZP-coder: the adaptive binary arithmetic coder under JB2, IW44 and BZZ.
Creating and converting DjVu files#
The DjVuLibre command-line tools are the standard way to work with DjVu files:
c44 -dpi 300 photo.ppm photo.djvu # color or grayscale image -> IW44 page
cjb2 -dpi 300 -lossy page.pbm page.djvu # black-and-white image -> JB2 page
djvm -c book.djvu p1.djvu p2.djvu # bundle pages into one document
ddjvu -format=tiff book.djvu book.tiff # render to TIFF (also pnm, pdf)
djvutxt book.djvu book.txt # extract the text layer
djvused book.djvu -e 'print-outline' # show the table of contents
djvudump book.djvu # list the chunks
- PDF to DjVu: pdf2djvu keeps text and links.
- DjVu to PDF:
ddjvu -format=pdfproduces image-only pages. To keep the OCR text and outline, use thedjvuCLI of djvu-rs (djvu render file.djvu --all --format pdf --output out.pdf) or dpsprep. - Scans to DjVu with color separation: commercial tools (ABBYY FineReader) and the open-source
didjvusplit pages into the background, mask and foreground layers.djvusedadds an OCR text layer from hOCR or other OCR output converted to its s-expression format.
Specifications and documentation#
- DjVu Reference, version 3: HTML transcription of the Lizardtech 2005 specification, with the original DjVu3Spec.djvu
- DjVuLibre documentation: man pages of all tools, including djvused, which documents the text, annotation and outline s-expressions
- DjVuLibre on SourceForge: source code and Windows builds
- IANA registration of image/vnd.djvu
- DjVu on Wikipedia
Software that opens DjVu files#
| Software | Windows | macOS | Linux | Web | Can | Notes |
|---|---|---|---|---|---|---|
| SumatraPDF | ✓ | view | free, open source; fast viewer for DjVu, PDF, EPUB and comic books | |||
| WinDjView | ✓ | view, convert | free, open source; tabs, thumbnails, export pages to images | |||
| DjView4 | ✓ | ✓ | ✓ | view, convert | DjVuLibre's viewer, free, open source; exports pages to other formats | |
| Okular | ✓ | ✓ | ✓ | view | KDE document viewer, free, open source | |
| GNOME Papers | ✓ | view | GNOME document viewer, successor of Evince | |||
| Evince | ✓ | view | older GNOME document viewer | |||
| Zathura | ✓ | view | keyboard-driven viewer, DjVu through the zathura-djvu plugin | |||
| KOReader | ✓ | ✓ | view | e-reader app for Kindle, Kobo, PocketBook and Android. Also on Android | ||
| DjVu.js Viewer | ✓ | view | in the browser, also a browser extension | |||
| STDU Viewer | ✓ | view | free for non-commercial use | |||
| DjVuLibre tools | ✓ | ✓ | ✓ | create, convert | c44, cjb2, djvm, ddjvu, djvused; command line, GPL | |
| pdf2djvu | ✓ | ✓ | convert | PDF to DjVu, keeps text and links | ||
| djvu-rs CLI | ✓ | ✓ | ✓ | create, convert | DjVu to PDF, EPUB, PNG; images to DjVu; MIT | |
| ABBYY FineReader PDF | ✓ | create, convert | commercial OCR; saves scans as DjVu |
Libraries#
Open-source libraries that read and write DjVu. See all DjVu libraries for a comparison.
| C/C++ | DjVuLibre |
|---|---|
| Python | djvu-rs, python-djvulibre |
| Rust | djvu-rs |
Related formats#
- PDF: the universal document format; scanned PDFs with JBIG2 compression come close to DjVu sizes
- TIFF: multi-page scans with G4 or LZW compression, much larger than DjVu
- JPEG 2000: wavelet image compression, like DjVu’s IW44 background layer
- CBZ: ZIP of page images, used for comics and sometimes for scanned books