Skip to main content

Crate ironpress

Crate ironpress 

Source
Expand description

§ironpress

Pure Rust HTML/CSS/Markdown to PDF converter. No browser, no system dependencies.

ironpress converts HTML (with CSS) and Markdown into PDF documents using a built-in layout engine. Unlike other Rust PDF crates, it does not shell out to headless Chrome or wkhtmltopdf.

§Features

  • All common HTML elements: headings, paragraphs, lists, tables, images, links, semantic sections
  • CSS support: selectors, flexbox, grid, floats, positioning, transforms, gradients, custom properties
  • Built-in Markdown parser (no external dependencies)
  • Custom TrueType font embedding
  • JPEG and PNG images (data URIs and local files)
  • Streaming output via std::io::Write
  • Async file I/O via optional tokio integration
  • HTML sanitization enabled by default

§Quick start

let pdf = ironpress::html_to_pdf("<h1>Hello</h1><p>World</p>").unwrap();
assert!(pdf.starts_with(b"%PDF"));

§Markdown

let pdf = ironpress::markdown_to_pdf("# Hello\n\nWorld").unwrap();
assert!(pdf.starts_with(b"%PDF"));

§Builder API

use ironpress::{HtmlConverter, PageSize, Margin};

let pdf = HtmlConverter::new()
    .page_size(PageSize::LETTER)
    .margin(Margin::uniform(54.0))
    .sanitize(false)
    .convert("<h1>Hello</h1>")
    .unwrap();

§Streaming output

let mut buf = Vec::new();
ironpress::html_to_pdf_writer("<h1>Hello</h1>", &mut buf).unwrap();
assert!(buf.starts_with(b"%PDF"));

§Custom fonts

use ironpress::HtmlConverter;

let ttf = std::fs::read("fonts/MyFont.ttf").unwrap();
let pdf = HtmlConverter::new()
    .add_font("MyFont", ttf)
    .convert(r#"<p style="font-family: MyFont">Custom text</p>"#)
    .unwrap();

Re-exports§

pub use error::IronpressError;
pub use types::Margin;
pub use types::PageSize;

Modules§

error
Error types for conversion failures.
types
Public types: page size, margins, and colors.

Structs§

HtmlConverter
Builder for HTML-to-PDF conversion with custom options.

Functions§

convert_file
Convert an HTML file to a PDF file using default settings.
convert_markdown_file
Convert a Markdown file to a PDF file using default settings.
html_to_pdf
Convert an HTML string to PDF bytes using default settings (A4, 1-inch margins).
html_to_pdf_writer
Convert an HTML string to PDF, writing output to any std::io::Write implementation.
markdown_to_pdf
Convert a Markdown string to PDF bytes using default settings (A4, 1-inch margins).
markdown_to_pdf_writer
Convert a Markdown string to PDF, writing output to any std::io::Write implementation.