Skip to main content

Crate hyper_render

Crate hyper_render 

Source
Expand description

§hyper-render

A Chromium-free HTML rendering engine for generating PNG and PDF outputs.

This library provides a simple, high-level API for rendering HTML content to images (PNG) or documents (PDF) without requiring a browser or Chromium dependency. It leverages the Blitz rendering engine for HTML/CSS parsing and layout.

§Features

  • PNG output: Render HTML to PNG images using CPU-based rendering
  • PDF output: Render HTML to PDF documents with vector graphics
  • No browser required: Pure Rust implementation, no Chromium/WebKit
  • CSS support: Flexbox, Grid, and common CSS properties via Stylo

§Quick Start

use hyper_render::{render, Config, OutputFormat};

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::default().format(OutputFormat::Pdf))?;
std::fs::write("output.pdf", pdf_bytes)?;

§Configuration

Use Config to customize the rendering:

use hyper_render::{Config, OutputFormat};

let config = Config::new()
    .width(1200)
    .height(800)
    .scale(2.0)  // 2x resolution for retina displays
    .format(OutputFormat::Png);

Structs§

Config
Configuration for HTML rendering.

Enums§

ColorScheme
Color scheme preference for rendering.
Error
Errors that can occur during HTML rendering.
OutputFormat
Output format for rendered content.

Functions§

render
Render HTML content to the specified output format.
render_to_pdf
Render HTML content to PDF format.
render_to_png
Render HTML content to PNG format.

Type Aliases§

Result
Result type alias for hyper-render operations.