Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Rust crate reference

The crates split docboss by concern. Most programs need docboss-core to open a document and one of the consumers after it.

CrateEntry points
docboss-coreopen(path), read(bytes), open_with/read_with(&Options { password }), detect(bytes) -> Format; re-exports the whole model
docboss-modelDocument and its parts; Styles::resolve_paragraph and resolve_run for effective formatting; Numbering::counter() for list labels; plain_text
docboss-outputto_text/write_text with TextOptions, to_markdown/write_markdown with MarkdownOptions, to_html/write_html with HtmlOptions, blocks_view, and with the serde feature to_json and blocks_json
docboss-layoutlayout_document(&Document) -> Layout, layout(&Document, &Arc<FontDatabase>), layout_with_options, fonts_for; Layout { pages, fonts, media, diagnostics } with positioned items in points
docboss-renderrender_page(&Layout, index, scale) -> Pixmap, render_pages (all cores), Renderer; Pixmap::encode(Format) and save; Format::{Png, Ppm, Bmp, Jpeg { quality }}
docboss-writeto_bytes(&Document), save, DocumentBuilder, Para, TableBuilder, markdown::to_docx
docboss-aioAsyncDocument::{open, from_bytes, open_url, open_url_with, from_backend}, read(&ReadOptions), load_media, part, part_names, bytes_fetched, requests; the http feature adds HttpBackend
docboss-docxread(bytes), read_with(bytes, Options): the WordprocessingML reader
docboss-docread(bytes), read_with_password, is_doc: the Word binary reader
docboss-zipArchive (reader), write (deterministic writer), crc32
docboss-xmlthe pull tokenizer used by the DOCX reader
docboss-cfbCompoundFile and property sets
docboss-cryptdecrypt(bytes, password) for encrypted DOCX
docboss-fontFont, FontDatabase with system discovery and substitution
docboss-metafileplay(bytes) -> Picture for WMF and EMF, text(&Picture), bitmap::{decode, decode_bmp, encode_bmp}
docboss-mtefread(stream) -> Option<Math>: the equation of an Equation Editor 3 object's Equation Native stream

Errors are thiserror enums per crate; docboss_core::Error wraps the readers' errors and adds Encrypted and Unsupported. No library function panics on input bytes: damaged input yields an error or a document with diagnostics.

use docboss_output::{to_html, HtmlOptions};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let options = docboss_core::Options { password: Some("secret".into()) };
    let doc = docboss_core::open_with("locked.docx", &options)?;
    for diagnostic in &doc.diagnostics {
        eprintln!("{:?} {}: {}", diagnostic.severity, diagnostic.location, diagnostic.message);
    }
    let html = to_html(&doc, &HtmlOptions { standalone: true, ..HtmlOptions::default() });
    std::fs::write("locked.html", html)?;
    Ok(())
}