Expand description
§rustium-pdf
Pure-Rust extraction of PDF page primitives — glyphs with geometry, vector paths, images — plus page rendering. No C library, no FFI, no global state.
It is what rustypaper reads PDFs with.
let doc = rustium_pdf::Document::open("paper.pdf")?;
let page = doc.page(0)?;
// Primitives are in user space (y-up); `page_matrix` converts to y-down device space.
for glyph in page.glyphs.iter().filter(|g| g.is_visible()) {
println!("{:?} at {:?} {}pt bold={}",
glyph.text, glyph.origin, glyph.font_size, glyph.flags.is_bold());
}
let png = page.render(&doc, rustium_pdf::RenderOptions::at_dpi(150.0))?.to_png()?;§Threading
Document is Send + Sync with no global state, so pages can be extracted and rendered
concurrently from one open document, without a lock around it.
§Text semantics
A word break the page expresses as a positioning gap rather than a space character is emitted
as a glyph flagged Glyph::is_generated_space, so word boundaries survive.
Page::text drops soft hyphens, which mark optional break points rather than content.
Primitives are in user space (y-up); Page::page_matrix converts to y-down page space.
§Fonts without embedded programs
A document may name Helvetica or Times and embed nothing. Extraction is unaffected: advances
come from built-in metrics for the standard 14. Rendering substitutes a system face, chosen
by style and preferring the metrically compatible Liberation family. Set RUSTIUM_FONT_DIR
to pin the search to fonts you ship. Positions always come from the document, never the
substitute, so a missing font shifts nothing.
§Known gaps
- Type1
/FontFileprograms yield metrics and text but no outlines; CFF and TrueType do. - Predefined non-Identity CJK CMaps fall back to the identity mapping.
JPXDecode,CCITTFaxDecodeandJBIG2Decodeimages are passed through undecoded and are skipped when rendering;DCTDecode(JPEG) and the byte filters are handled.- Clipping is tracked as a bounding rectangle, not an arbitrary path.
Re-exports§
pub use document::Document;pub use error::Error;pub use error::Result;pub use font::Font;pub use font::FontFlags;pub use geom::Matrix;pub use geom::Point;pub use geom::Rect;pub use object::Dict;pub use object::Object;pub use page::Glyph;pub use page::ImageData;pub use page::ImageItem;pub use page::Page;pub use page::PathItem;pub use render::RenderOptions;pub use render::Rendered;
Modules§
- content
- Content-stream tokenization: a flat sequence of
operands... operator, with inline images (BI ... ID ... EI) folded into single operations. - crypt
- The standard security handler: RC4 and AES, revisions 2 through 6.
- document
- The document: catalog, page tree, and per-page access.
- error
- Error type. One enum, no dependency on an error-derive crate.
- filters
- Stream filters.
- font
- Fonts: mapping character codes to advances, Unicode and glyph outlines.
- geom
- Points, rectangles and 2×3 affine matrices in PDF’s row-vector convention.
- lexer
- A byte cursor and recursive-descent reader for COS syntax.
- object
- The COS object model: everything a PDF body is made of.
- page
- Page primitives: interpreting content streams into glyphs, paths and images.
- parser
- File structure: header, cross-reference tables and streams, object streams, trailer chain, and a brute-force recovery scan for files whose xref is wrong — which is common enough that every serious reader has one.
- render
- Rasterising a page to pixels.