ironpress
Pure Rust HTML/CSS/Markdown to PDF converter. No browser, no system dependencies.
Other Rust PDF crates shell out to headless Chrome or wkhtmltopdf. ironpress does it natively with a built-in layout engine. No C libraries, no binaries to install, just cargo add ironpress.
Table of Contents
- Quick Start
- API Reference
- Markdown to PDF
- HTML Elements
- CSS Support
- Images
- Tables
- Fonts
- Security
- How It Works
- Roadmap
- License
Quick Start
use html_to_pdf;
let pdf_bytes = html_to_pdf.unwrap;
write.unwrap;
API Reference
One-liner functions
// HTML string to PDF bytes
let pdf = html_to_pdf.unwrap;
// Markdown string to PDF bytes
let pdf = markdown_to_pdf.unwrap;
// HTML file to PDF file
convert_file.unwrap;
// Markdown file to PDF file
convert_markdown_file.unwrap;
Builder API
use ;
let pdf = new
.page_size // default: A4
.margin // default: 72pt (1 inch)
.sanitize // default: true
.convert
.unwrap;
Page sizes
use PageSize;
A4 // 595.28 x 841.89 pt (default)
LETTER // 612.0 x 792.0 pt
LEGAL // 612.0 x 1008.0 pt
new // custom
Margins
use Margin;
default // 72pt on all sides (1 inch)
uniform // same value on all sides
new // individual values in pt
Markdown to PDF
Built-in Markdown parser with zero external dependencies.
let pdf = markdown_to_pdf
fn main() { println!("hello"); }
[Link text](https://example.com)
"#).unwrap();
Supported Markdown syntax: headings (# to ######), bold (**), italic (*), bold+italic (***), inline code, fenced code blocks, links, images, unordered lists (-, *, +), ordered lists, blockquotes, and horizontal rules.
HTML Elements
| Category | Elements |
|---|---|
| Headings | <h1> through <h6> with default sizes and bold |
| Block containers | <p>, <div>, <blockquote>, <pre>, <figure>, <figcaption>, <address> |
| Semantic sections | <section>, <article>, <nav>, <header>, <footer>, <main>, <aside>, <details>, <summary> |
| Inline formatting | <strong>, <b>, <em>, <i>, <u>, <small>, <sub>, <sup>, <code>, <abbr>, <span> |
| Text decoration | <del>, <s> (strikethrough), <ins> (underline), <mark> (highlight) |
| Links | <a> with clickable PDF link annotations |
| Images | <img> with JPEG and PNG support (data URIs and local files) |
| Line breaks | <br>, <hr> |
| Lists | <ul>, <ol> with nested support, <li>, <dl>, <dt>, <dd> |
| Tables | <table>, <thead>, <tbody>, <tfoot>, <tr>, <td>, <th>, <caption> with colspan, rowspan, and cell borders |
CSS Support
Properties
| Category | Properties |
|---|---|
| Typography | font-size, font-weight, font-style, font-family |
| Colors | color, background-color |
| Box model | margin, padding, border, border-width, border-color |
| Layout | text-align, line-height, display |
| Decoration | text-decoration (underline, line-through) |
| Page control | page-break-before, page-break-after |
All properties support shorthand notation. Margin and padding accept 1, 2, 3, or 4 values. Border accepts width style color shorthand.
<style> blocks
Selectors
| Type | Example |
|---|---|
| Tag | p, h1, div |
| Class | .highlight, .intro |
| ID | #title, #nav |
| Combined | p.highlight, div#main |
| Comma-separated | h1, h2, h3 |
Values
| Type | Examples |
|---|---|
| Colors | red, navy, darkblue, #f00, #ff0000, rgb(255, 0, 0) |
| Units | 12pt, 16px, 1.5em |
| Keywords | bold, italic, center, none |
Media queries
@media print rules are applied (since PDF is print output). @media screen rules are ignored.
Images
JPEG and PNG images are supported via data URIs and local file paths.
<!-- Data URI -->
<!-- Local file -->
Images are embedded directly in the PDF. JPEG uses DCTDecode, PNG uses FlateDecode with PNG predictors. Width and height attributes are converted from px to pt.
Tables
Full table support with sections, spanning, and styling.
NameRoleStatus
Alice
Engineer
Active
On project X
Bob
Designer
Active
Features: <thead>, <tbody>, <tfoot> sections, colspan and rowspan attributes, bold headers in <th>, cell borders, background colors, and padding.
Fonts
ironpress uses the 14 standard PDF fonts (no font embedding required). CSS font-family values are mapped to the closest match:
| PDF Font | CSS Values |
|---|---|
| Helvetica | arial, helvetica, sans-serif, verdana, tahoma, roboto, open sans, inter, system-ui, and more |
| Times-Roman | serif, times new roman, georgia, garamond, palatino, merriweather, lora, and more |
| Courier | monospace, courier new, consolas, fira code, jetbrains mono, source code pro, menlo, and more |
Each family includes regular, bold, italic, and bold-italic variants (12 fonts total). Unknown font names default to Helvetica.
Security
HTML is sanitized by default before conversion:
<script>,<iframe>,<object>,<embed>,<form>tags are stripped<style>tags are preserved but dangerous CSS (@import, externalurl(),expression()) is removed- Event handlers (
onclick,onload, etc.) are removed javascript:URLs are neutralized- Input size (10 MB) and nesting depth (100 levels) are limited
Sanitization can be disabled with .sanitize(false) if you trust the input.
How It Works
Input --> Sanitize --> Parse (html5ever) --> Extract <style> --> Style cascade --> Layout engine --> PDF
- Sanitize the input HTML to remove dangerous elements
- Parse HTML into a DOM tree using html5ever, extracting
<style>blocks - Resolve styles by cascading: tag defaults, then
@media printrules, then stylesheet rules, then inline CSS - Layout elements with text wrapping, page breaks, tables, lists, images, and the CSS box model
- Render to PDF 1.4 with text, graphics, link annotations, and embedded images
For Markdown input, a built-in parser converts Markdown to HTML first (no external dependencies).
Roadmap
v0.5 -- New input formats
- Plain text (TXT) to PDF
- CSV to PDF (auto-formatted tables)
- PNG/JPEG to PDF (full-page image conversion)
- XML to PDF
v0.6 -- Vector graphics and e-books
- SVG rendering (paths, shapes, text, basic CSS)
- EPUB to PDF
v0.7 -- Office documents
- DOCX to PDF
- XLSX to PDF (spreadsheet tables)
Planned improvements
- Remote image loading via URL (behind a feature flag)
- TrueType/OpenType font embedding
- CSS
floatandpositionproperties - Advanced CSS selectors (descendant, child, attribute)
- Table auto-sizing based on content width
- Hyphenation and text justification
License
MIT