A Chromium-free HTML rendering engine for generating PNG and PDF outputs in pure Rust.
- No browser required β Pure Rust implementation, no Chromium/WebKit dependency
- PNG output β High-quality raster images via CPU-based rendering
- PDF output β Vector PDF documents with embedded fonts
- Modern CSS β Flexbox, Grid, and common CSS properties via Stylo (Firefox's CSS engine)
- Simple API β Single function call to render HTML to bytes
Add to your Cargo.toml:
[dependencies]
hyper-render = "0.1"Or with specific features:
[dependencies]
hyper-render = { version = "0.1", default-features = false, features = ["png"] }use hyper_render::{render, Config, OutputFormat};
fn main() -> Result<(), hyper_render::Error> {
let html = r#"
<html>
<body style="font-family: sans-serif; padding: 20px;">
<h1 style="color: navy;">Hello, World!</h1>
<p>Rendered without Chromium.</p>
</body>
</html>
"#;
// Render to PNG
let png_bytes = render(html, Config::default())?;
std::fs::write("output.png", png_bytes)?;
// Render to PDF
let pdf_bytes = render(html, Config::new().format(OutputFormat::Pdf))?;
std::fs::write("output.pdf", pdf_bytes)?;
Ok(())
}// Render to any format based on config
render(html: &str, config: Config) -> Result<Vec<u8>>
// Convenience functions
render_to_png(html: &str, config: Config) -> Result<Vec<u8>>
render_to_pdf(html: &str, config: Config) -> Result<Vec<u8>>use hyper_render::{Config, OutputFormat, ColorScheme};
let config = Config::new()
.width(1200) // Viewport width in pixels
.height(800) // Viewport height in pixels
.size(1200, 800) // Set both at once
.scale(2.0) // Scale factor (2.0 for retina)
.format(OutputFormat::Png) // Output format: Png or Pdf
.color_scheme(ColorScheme::Light) // Light or Dark mode
.auto_height(true) // Auto-detect content height
.background([255, 255, 255, 255]) // RGBA background color
.transparent(); // Transparent background| Format | Status | Description |
|---|---|---|
OutputFormat::Png |
β Full | Raster image via Vello CPU renderer |
OutputFormat::Pdf |
β Full | Vector PDF with embedded fonts and backgrounds |
git clone https://github.com/thomasmost/hyper-render
cd hyper-render
cargo buildcargo run --example simpleThis generates output.png and output.pdf in the current directory.
# Create a test HTML file
echo '<html><body style="background: #667eea; color: white; padding: 40px; font-family: system-ui;"><h1>My Page</h1><p>Hello from hyper-render!</p></body></html>' > test.html
# Render to PNG
cargo run --example from_file -- test.html output.png
# Render to PDF
cargo run --example from_file -- test.html output.pdfcargo testcargo doc --openhyper-render composes several best-in-class Rust crates:
HTML String
β
html5ever (HTML parsing)
β
Stylo (CSS parsing & cascade - from Firefox)
β
Taffy (Flexbox/Grid layout)
β
Blitz (DOM + rendering coordination)
β
βββββββββββββββββββ¬ββββββββββββββββββ
β Vello CPU β Krilla β
β (rasterizer) β (PDF writer) β
ββββββββββ¬βββββββββ΄βββββββββ¬βββββββββ
β β
PNG PDF
Run benchmarks locally:
# Full benchmark suite
cargo bench --all-features
# Specific benchmark group
cargo bench full_pipeline
# Generate HTML reports
cargo bench --all-features # Reports saved to target/criterion/| Benchmark | Time |
|---|---|
| PNG render (small HTML) | ~10 ms |
| PNG render (medium HTML) | ~13 ms |
| PNG render (large HTML, 50 items) | ~13 ms |
| PDF render (small HTML) | ~9 ms |
| PDF render (medium HTML) | ~9 ms |
| PDF render (large HTML, 50 items) | ~12 ms |
Scaling impact (800x600 base):
| Scale | Time | Pixels |
|---|---|---|
| 1x | ~13 ms | 480K |
| 2x | ~21 ms | 1.9M |
| 3x | ~32 ms | 4.3M |
Dimension impact:
| Size | Time | Throughput |
|---|---|---|
| 400x300 | ~11 ms | 10M px/s |
| 800x600 | ~13 ms | 35M px/s |
| 1920x1080 | ~18 ms | 115M px/s |
| Features | Library Size |
|---|---|
| none | 250 KB |
| png | 544 KB |
| 513 KB | |
| png,pdf (default) | 767 KB |
Check detailed size breakdown:
cargo install cargo-bloat
cargo bloat --release --all-features -n 20- PNG rendering scales with pixel count: O(width Γ height Γ scaleΒ²)
- PDF rendering scales with DOM complexity: O(nodes Γ text_length)
- HTML parsing is generally fast; layout (Stylo/Taffy) dominates small documents
- Font caching in PDF reduces repeated text rendering overhead
You may see ERROR: Unexpected token messages when rendering HTML with non-standard CSS properties (e.g., mso-font-alt for Microsoft Office). These warnings come from the HTML parser and do not affect rendering β the output is still generated correctly.
To suppress these warnings, redirect stderr:
cargo run --example from_file -- input.html output.png 2>/dev/null- JavaScript β Not supported (by design)
- Web fonts β System fonts only;
@font-facenot yet supported - Images β External image loading not yet implemented
- Some CSS β Advanced features like
position: sticky, complex transforms may not work
Core rendering stack:
- Blitz β HTML/CSS rendering engine
- Stylo β Firefox's CSS engine
- Taffy β Flexbox/Grid layout
- Vello β 2D graphics (CPU renderer)
- Krilla β PDF generation
MIT OR Apache-2.0