Render any Rails view to PDF, exactly as the browser sees it.

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) %>

What it does

Background rendering (new in 4.0)

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

Full write-up, with per-adapter setup for Solid Queue and Sidekiq, in Background PDF jobs with ActiveJob: Sidekiq, Solid Queue, and storage adapters.

How it compares

CapabilityHtmlToPdfWickedPdf / PDFKitGroverPrawn
Renders your existing view✓✓✓— (own DSL)
Rendering engineChrome (current)wkhtmltopdf (unmaintained)Chrome via Puppeteern/a
Modern CSS (flexbox/Grid)✓—✓n/a
Extra runtime neededChrome/Chromium onlywkhtmltopdf binaryChrome + Node.js + Puppeteernone
Pooled browser (no per-request spawn)✓n/adepends on setupn/a
around_action-safe callback ordering✓variesvariesn/a

Full breakdown in Choosing a Rails HTML-to-PDF gem.

Guides

Links