Rust¶
Add the crate with cargo add kolinsky. An Engine holds the fonts and the resource loader; build it once
and use it for every document.
use kolinsky::{Engine, Input, PdfOptions, RenderOptions};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let engine = Engine::new();
let input = Input::Path("hello.html".into());
let rendered = engine.render(input, &RenderOptions::default(), &PdfOptions::default())?;
for d in &rendered.diagnostics {
eprintln!("{}: {}", d.code, d.message);
}
std::fs::write("hello.pdf", rendered.output)?;
Ok(())
}
render returns the PDF bytes with the diagnostics of the call (missing resources, unsupported CSS and the
like). An error is returned when the input cannot be loaded or, with RenderOptions::strict, when a
diagnostic of a strict category is found.
Options¶
RenderOptions sets how the document is laid out (user stylesheets, media type, the default page size and
margin, network access); PdfOptions sets what the PDF contains (metadata, standards, tags, outline,
pages, attachments).
use kolinsky::{Engine, Input, PdfOptions, PdfStandard, RenderOptions};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut options = RenderOptions::default();
options.default_page.size = Some("A5".into());
let mut pdf = PdfOptions::default();
pdf.title = Some("Invoice 2026-042".into());
pdf.standards = vec![PdfStandard::PdfUa1];
pdf.tagged = true;
let rendered = Engine::new().render(Input::Path("hello.html".into()), &options, &pdf)?;
std::fs::write("invoice.pdf", rendered.output)?;
Ok(())
}
Every type and option is documented on docs.rs.