Skip to main content

Crate stet_pdf_reader

Crate stet_pdf_reader 

Source
Expand description

PDF parser, page navigator, and content stream interpreter.

stet-pdf-reader is a self-contained PDF reader: it opens a PDF, walks its object graph, and interprets each page’s content stream into a stet_graphics::display_list::DisplayList that any downstream consumer (rasterizer, PDF writer, custom output device) can render.

The crate intentionally has no dependency on stet-core — it uses only stet-fonts (font parsing) and stet-graphics (display list and ICC types), so it can be used as a standalone PDF parser/renderer without pulling in the PostScript interpreter.

§Quick start

use stet_pdf_reader::PdfDocument;

let data = std::fs::read("document.pdf")?;
let doc = PdfDocument::from_bytes(&data)?;

for page in 0..doc.page_count() {
    let display_list = doc.render_page(page, 150.0)?;
    // …consume the display list (rasterize, convert, inspect, etc.)
}

With the default render feature enabled, PdfDocument::render_page_to_rgba skips the display-list-handling boilerplate and produces RGBA pixels directly via stet-render.

§Encrypted PDFs

from_bytes / from_bytes_with_icc try the empty password. If the file uses a non-empty user password they return PdfError::PasswordRequired; the caller can then prompt the user and retry with PdfDocument::from_bytes_with_password:

use stet_pdf_reader::{PdfDocument, PdfError};
use stet_graphics::icc::IccCache;

let data = std::fs::read("encrypted.pdf")?;
let doc = match PdfDocument::from_bytes(&data) {
    Ok(doc) => doc,
    Err(PdfError::PasswordRequired) => {
        let pw = prompt_user_for_password();
        PdfDocument::from_bytes_with_password(&data, IccCache::new(), pw.as_bytes())?
    }
    Err(e) => return Err(e.into()),
};

RC4 (40/128-bit), AES-128, and AES-256 (R=5/6) are all supported.

§Acknowledgements

JPEG 2000, JBIG2, and CCITT-Fax stream decoding use the hayro-jpeg2000, hayro-jbig2, and hayro-ccitt crates from the hayro PDF renderer by Laurenz Stampfl. Big thanks to the hayro project for factoring those decoders out as reusable crates — stet-pdf-reader would not cover the full PDF stream-filter surface without them.

Re-exports§

pub use error::PdfError;
pub use objects::PdfDict;
pub use objects::PdfObj;
pub use page_tree::PageInfo;

Modules§

content
PDF content stream interpreter.
crypto
PDF encryption: Standard security handler (RC4 + AES-128/256).
error
PDF parsing error types.
filters
Stream decode filter chain for PDF streams.
lexer
PDF tokenizer.
objects
PDF object model for reading.
page_tree
PDF page tree traversal with attribute inheritance.
resolver
Indirect object resolution with lazy caching and stream decompression.
resources
PDF resource lookup helpers.
xref
PDF cross-reference table and trailer parsing.

Structs§

PdfDocument
A parsed PDF document.

Type Aliases§

FontProvider
Font data provider: maps a font file name (e.g. “NimbusSans-Regular”) to raw .t1 bytes.