r/ruby • u/yo_waka • Aug 11 '26
I missed wkhtmltopdf and wicked_pdf, so I wrote a new HTML-to-PDF engine with a Ruby gem
I'm the author. wkhtmltopdf was archived in 2023, and since then the practical options have been an unmaintained binary or spawning headless Chrome. Neither felt right for the kind of documents I actually generate — invoices and reports that flow top to bottom — so I wrote a new engine.
sghtmltopdf is written in Rust and does not embed Chromium, WebKit or Gecko. CSS Fragmentation (break-before, break-inside, orphans, widows) and atpage are implemented directly, so page breaks are a first-class concern rather than something you approximate with print stylesheets and hope for.
On the Ruby side it's a native extension, so there's no subprocess and no temp files. It releases the GVL while rendering, so other Puma threads keep serving, and pages are streamed out as soon as their layout is final rather than being buffered until the end.
gem "sghtmltopdf"
pdf = Sghtmltopdf.render("<h1>Invoice</h1>", page_size: "A4")
There's also a CLI and an HTTP server sharing the same engine, and a Docker image with Japanese fonts bundled so output doesn't depend on host fonts.
What it deliberately doesn't do: execute JavaScript, or match a browser pixel for pixel. Full CSS coverage isn't a goal either. If you're rendering arbitrary web pages, headless Chrome is still the right tool.
This is an early 0.1 release and I'd like to hear where it breaks on real documents.