Skip to content
Inkoxide

Search covers every page and heading of the docs. Use ↑ ↓ and ↵.

The engine in Rust

The inkoxide crate: a document tree, fonts and images in, PDF bytes out, with no I/O of its own.

Edit this page

The Inkoxide PDF engine: a document tree in, PDF bytes out. It does the typesetting, so text shaping, line breaking, flexbox and grid layout, pagination and PDF output. It does no I/O: you give it the document, the fonts and the images as bytes.

This is the engine behind the npm packages inkoxide (Node.js), @inkoxide/wasm (browsers) and @inkoxide/render, which renders templates of React, Vue, Svelte and Angular.

use inkoxide::{FontStore, ImageStore, InputFormat, RenderOptions};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let doc = r#"{"version":1,"fonts":[{"id":"Inter-Regular","family":"Inter"}],
      "pages":[{"size":{"width":595,"height":842},"children":[
        {"type":"text","runs":[{"text":"Hello from Inkoxide","font":"Inter-Regular","size":24}]}]}]}"#;

    let mut fonts = FontStore::new();
    fonts.register("Inter-Regular", std::fs::read("Inter-Regular.ttf")?)?;

    let options = RenderOptions::default();
    let pdf = inkoxide::render(doc.as_bytes(), InputFormat::Json, &options, &fonts, &ImageStore::new())?;
    std::fs::write("hello.pdf", pdf)?;
    Ok(())
}

The same input gives the same bytes: no date is written unless the document or the options set one. validate reports the problems in a document, each with its path, and render never returns a partial PDF.

Features

  • msgpack (default): MessagePack input, with the same structure as the JSON.
  • embedded-hyphenation (default): the built-in TeX hyphenation patterns (1.2 MB). Without it, HyphenationStore::register_builtin gives them at run time.

Documentation

Licence

MIT.

Synced from crates/core/README.md in the inkoxide repository.