The journal · 25 November 2026 · 6 min read
HTML to PDF in Rust With Headless Chrome or an API and What a Year Costs
Rust has no pure HTML to PDF engine for invoices, so every route ends at a browser. Self-hosting Chrome costs about $5,360 in year one at 50,000 renders a month, an API about $988.
Live demo
Runs in your browser. Nothing is uploaded. One PDF free to try, then a plan.
Your HTML
Live preview
Your PDF is downloading. That was the free one. The Starter plan converts as many as you need, for $49 a month or $288 a year, half price.
See the planSitePDF is an HTML to PDF API, and this article answers one question a Rust team asks before buying anything: what does it cost to turn HTML into PDF from Rust, and when is calling an API cheaper than running Chromium yourself. The short version is that Rust has no pure Rust HTML layout engine good enough for invoices, so every route ends at a browser, and the real choice is who operates that browser.
The short answer
Use a Chromium based renderer for HTML that must match the web view. In Rust that means either driving Chrome with a crate such as headless_chrome or chromiumoxide, or sending the HTML to a rendering API with an ordinary HTTP client. Crates that draw PDFs directly, such as printpdf or genpdf, give you a drawing API, not an HTML converter, so they suit labels and fixed forms rather than invoices that share a template with the app.
What are the real options for HTML to PDF in Rust?
| Route | What you operate | Handles modern CSS and JS | Fits |
|---|---|---|---|
| Drawing crate (printpdf, genpdf) | Nothing external, you lay out every element in code | No HTML input at all | Labels, certificates, fixed forms |
| Headless Chrome crate | Chrome or Chromium in your image, a pool, timeouts, fonts | Yes, same engine as the browser | Teams that already run containers with spare capacity |
| wkhtmltopdf called as a process | An archived binary and its security exposure | Old WebKit, weak on modern CSS | Legacy layouts only |
| Rendering API from reqwest | An API key and one HTTP call | Yes, managed Chromium | Invoices, statements, reports at steady volume |
The wkhtmltopdf project is archived and carries a published SSRF advisory, CVE-2022-35583, which is why we do not recommend starting new work on it. The wkhtmltopdf alternative page covers the migration in detail.
What does driving Chrome from Rust involve?
The crate launches a Chrome process, opens a tab, loads your HTML, waits, and calls the DevTools print method. The code is short. The operational work around it is not.
// Cargo: headless_chrome
let browser = Browser::default()?;
let tab = browser.new_tab()?;
tab.navigate_to("data:text/html;base64,...")?;
tab.wait_until_navigated()?;
let pdf = tab.print_to_pdf(None)?;
std::fs::write("invoice.pdf", pdf)?;
In production you also need Chromium installed in the container image, system fonts for every script your customers use, a cap on concurrent tabs so a month-end batch does not exhaust memory, a restart policy for a browser that hangs, and a decision on what happens when a render times out. A scratch or distroless Rust image no longer works, because Chromium brings shared libraries with it. The image grows from a few megabytes to several hundred.
What does a self-hosted Chrome pool cost in year one?
These are planning assumptions, not measurements, so replace them with your own. A team renders 50,000 invoices and statements a month. They spend 20 hours building the pool, timeouts, font set and monitoring, then 2 hours a month on upgrades and incidents. Labor is priced at $100 an hour. They add 2 extra containers at $40 a month each to absorb the month-end peak.
| Item | Basis | Year one cost |
|---|---|---|
| Build the Chrome pool | 20 hours at $100 | $2,000 |
| Upgrades and incidents | 2 hours a month at $100 | $2,400 |
| Extra containers for peak | 2 at $40 a month | $960 |
| Self-hosted total | $5,360 | |
| Integrate the API from Rust | about 4 hours at $100 | $400 |
| SitePDF Growth, 50,000 renders a month | $99 list, $588 billed yearly | $588 |
| API total | $988 |
Only the $588 repeats in year two, while the self-hosted labor and containers repeat in full. The number to challenge is the maintenance hours: if your platform team already runs a browser fleet for other work, the marginal figure is lower and self-hosting can win.
How do you call a rendering API from Rust?
With reqwest and serde_json it is one POST. Send the HTML you already render with a template crate such as Askama or Tera, get back a link to the PDF.
let res = reqwest::Client::new()
.post("https://api.sitepdf.com/v1/render")
.bearer_auth(std::env::var("SITEPDF_KEY")?)
.json(&serde_json::json!({
"html": invoice_html,
"format": "Letter",
"archive": true
}))
.send().await?
.json::<serde_json::Value>().await?;
The render runs in managed Chromium, so flexbox, web fonts and chart scripts behave as they do in your browser. With archive set to true the render is also stored with its capture time, which is useful when an invoice has to be produced months later. The PDF generator API page describes the same flow for other stacks, and the Go version is the closest comparison for compiled-language teams. JVM teams can read the Kotlin cost breakdown, which adds library licenses to the math.
The same build or buy question applies on Apple platforms, covered in HTML to PDF in Swift.
Who this is for and who it is not for
It is for Rust teams that produce invoices, statements or reports from HTML and would rather pay a flat monthly price than maintain a browser pool. It is not for teams that draw fixed-position documents in code, need PDF signing, or must keep all data inside their own network. For those, the drawing crates or a self-hosted browser are the better route.
What to do this week
Take one real invoice, render it through SitePDF from a short Rust test, and compare it with your current output. Start on the pricing page if you want the plan that fits your volume, or read the chromedp cost breakdown to see the same math for Go.
For the standards behind the print step, the Chrome team documents the DevTools Page.printToPDF method that the Rust crates call.
On a C++ stack the same choice appears with Qt WebEngine and CEF, priced in the C++ HTML to PDF cost comparison. A Delphi team faces the same trade with WebView2 or CEF4Delphi, priced in the Delphi HTML to PDF cost article.
Frequently asked questions
How do I convert HTML to PDF in Rust?
Render the HTML in a browser engine. In Rust you either drive Chrome with a crate such as headless_chrome and call its print method, or POST the HTML to a rendering API and receive the PDF. Pure drawing crates do not accept HTML.
Is there a pure Rust HTML to PDF library?
Not one that matches browser layout for flexbox, grid and web fonts. Crates such as printpdf and genpdf generate PDFs from drawing calls. For HTML that must look like your web page, you need a Chromium based renderer.
Can I run headless Chrome from a Rust Docker image?
Yes, but the image must include Chromium, its shared libraries and fonts, so a scratch or distroless base no longer works. Plan for a concurrency cap and a restart policy as well.
When is an HTML to PDF API cheaper than self-hosting?
At steady volume with no existing browser fleet, because maintenance labor dominates the cost. In the example above, 50,000 renders a month cost $988 in year one through the API against $5,360 self-hosted, using stated assumptions.
Written by the team behind SitePDF, an HTML to PDF API that archives every page it renders. The in-browser converter is free to try, and API plans start at $49 a month, half price billed yearly.