hyper-render
A Chromium-free HTML rendering engine for generating PNG and PDF outputs in pure Rust.
Features
- 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
Installation
Add to your Cargo.toml:
[]
= "0.1"
Or with specific features:
[]
= { = "0.1", = false, = ["png"] }
Quick Start
use ;
API
Main Functions
// Render to any format based on config
render // Convenience functions
render_to_png
Configuration
use ;
let config = new
.width // Viewport width in pixels
.height // Viewport height in pixels
.size // Set both at once
.scale // Scale factor (2.0 for retina)
.format // Output format: Png or Pdf
.color_scheme // Light or Dark mode
.auto_height // Auto-detect content height
.background // RGBA background color
.transparent; // Transparent background
Output Formats
| Format | Status | Description |
|---|---|---|
OutputFormat::Png |
✅ Full | Raster image via Vello CPU renderer |
OutputFormat::Pdf |
✅ Full | Vector PDF with embedded fonts and backgrounds |
Try It Yourself
Clone and Build
Run the Example
This generates output.png and output.pdf in the current directory.
Render Your Own HTML
# Create a test HTML file
# Render to PNG
# Render to PDF
Run Tests
Generate Documentation
Architecture
hyper-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
Performance
Benchmarks
Run benchmarks locally:
# Full benchmark suite
# Specific benchmark group
# Generate HTML reports
Sample Results (M1 MacBook Pro)
| 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 |
Build Size
| Features | Library Size |
|---|---|
| none | 250 KB |
| png | 544 KB |
| 513 KB | |
| png,pdf (default) | 767 KB |
Check detailed size breakdown:
Performance Characteristics
- 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
Known Issues
HTML Parser Warnings
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:
Limitations
- 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
Dependencies
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
License
MIT OR Apache-2.0