A pooled headless Chrome instance instead of an abandoned wkhtmltopdf binary — real CSS, real layout, real fonts, no separate renderer to compile or package. Generate it inline, or hand it to a background job with job status tracking and S3/ActiveStorage storage.
Any controller action. The same view. A PDF instead of HTML. HtmlToPdf renders the exact view your app already has — the same ERB, the same CSS, the same layout — and converts it with real headless Chrome instead of wkhtmltopdf's years-out-of-date, unmaintained WebKit build. Flexbox, CSS Grid, and modern fonts render the way they actually look in a browser, because it is a browser.
gem install htmlToPdf
class ApplicationController < ActionController::Base
include HtmlToPdf
around_action :html_to_pdf
end
<%= link_to "Download PDF", invoice_path(@invoice, format: :pdf) %>
pdf_options[:layout]).around_action, not a before_action that quietly
re-runs your action on a throwaway controller — every other callback, instance variable, and
rescue_from works exactly like it does for an ordinary request.For PDFs slow enough that a caller shouldn't hold a connection open, or that should land in storage instead of streaming back directly:
HtmlToPdf.generate_later(
controller: InvoicesController,
action: :show,
assigns: { invoice: invoice },
store: { adapter: :active_storage, record: invoice, attachment: :pdf }
)
HtmlToPdf::JobStatus.find(job.job_id) # => state/result/error, readable from any process
HtmlToPdf::GenerateJob is a plain ActiveJob::Base
subclass — no Sidekiq- or Solid-Queue-specific code anywhere, so it runs under whichever
queue adapter your app already configures.print_options value is discarded
immediately instead, since retrying a validation error can't fix it.queued → processing →
completed/failed) via a pluggable store, readable from a different
process than the one running the job — the normal case with a real worker process.:active_storage (any
has_one_attached, whatever service your app already uses) and a true-optional
:s3 adapter (direct upload, no ActiveStorage dependency forced on you).config.max_concurrent_renders caps how many conversions run
against the shared browser at once — useful once a worker pool, not just a web request, can
call into it concurrently.Full write-up, with per-adapter setup for Solid Queue and Sidekiq, in Background PDF jobs with ActiveJob: Sidekiq, Solid Queue, and storage adapters.
| Capability | HtmlToPdf | WickedPdf / PDFKit | Grover | Prawn |
|---|---|---|---|---|
| Renders your existing view | ✓ | ✓ | ✓ | — (own DSL) |
| Rendering engine | Chrome (current) | wkhtmltopdf (unmaintained) | Chrome via Puppeteer | n/a |
| Modern CSS (flexbox/Grid) | ✓ | — | ✓ | n/a |
| Extra runtime needed | Chrome/Chromium only | wkhtmltopdf binary | Chrome + Node.js + Puppeteer | none |
| Pooled browser (no per-request spawn) | ✓ | n/a | depends on setup | n/a |
around_action-safe callback ordering | ✓ | varies | varies | n/a |
Full breakdown in Choosing a Rails HTML-to-PDF gem.
Renderer/Converter/JobStatus/Storage),
concrete Solid Queue and Sidekiq setup, both storage adapters in detail, and a
troubleshooting section for the mistakes that actually happen in production.around_action.