RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

sghtmltopdf: an HTML to PDF renderer in Rust, with a Ruby gem and Rails integration

wkhtmltopdf was archived in 2023, leaving Rails apps stuck between an unmaintained binary and spawning headless Chrome. I built sghtmltopdf, a new rendering engine written in Rust that implements CSS Fragmentation and @page directly, so page breaks, orphans and widows are first-class rather than approximated. It ships as a CLI, an HTTP server, and a Ruby gem (gem "sghtmltopdf").

The gem runs in-process via a native extension, releases the GVL while rendering so other Puma threads keep working, and streams each page out as soon as its layout is final, so memory stays flat on large documents. A :pdf renderer is registered for Rails in the spirit of wicked_pdf, and existing controllers often need no changes.

Future-goals: JavaScript execution and pixel parity with browsers. It targets documents that flow top to bottom — invoices, receipts, reports. This is an early 0.1 release, MIT licensed. Docs: https://waka.github.io/sghtmltopdf/en/

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in