pdforge logo

pdforge

Product

Resources

Integrations

Language Guide

Language Guide

C#

C#

How to Convert HTML to PDF Using Ruby on Rails Best Gems in 2025

Marcelo Abreu, founder of pdforge

Marcelo | Founder of pdforge

Marcelo | Founder of pdforge

Sep 17, 2025

Sep 17, 2025

Convert HTML to PDF using Ruby on Rails has become an essential requirement for SaaS startups and enterprise applications alike. In 2025, developers are seeking Rails-compatible libraries that integrate seamlessly into their applications and deliver consistent PDF output from HTML templates. Whether building invoices, reports, or dashboards, Rails developers want solutions that are reliable, scalable, and easy to maintain.

Best html to pdf gems Ruby on rails 2025
Best html to pdf gems Ruby on rails 2025

Overview of top HTML to PDF Conversion Libraries for Ruby on Rails

Rails developers can choose between libraries that render HTML into PDF using browsers or underlying engines. This is different from older Ruby PDF libraries such as Prawn or HexaPDF, which require low-level PDF building or limited styling. With HTML-based rendering, teams can rely on CSS, JavaScript, and existing ERB or HAML templates to produce professional-looking documents.

We’ll explore the top Ruby on Rails libraries for HTML to PDF conversion in 2025:

  • WickedPDF

  • Grover

  • Puppeteer-Ruby

WickedPDF

Wicked PDF Gem Info

WickedPDF has been a staple in the Rails community for years. It is a Ruby gem that integrates wkhtmltopdf with Rails, allowing developers to render ERB templates directly into PDFs. It supports standard CSS and JavaScript, though some modern web features may require workarounds. Its strength lies in stability and deep Rails integration, making it a common choice for applications needing invoices or reports.

Example:

# Gemfile
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
# Controller
class InvoicesController < ApplicationController
  def show
    @invoice = Invoice.find(params[:id])
    respond_to do |format|
      format.html
      format.pdf do
        render pdf: "invoice",
               template: "invoices/show.html.erb",
               margin: { top: 20, bottom: 20, left: 10, right: 10 },
               header: { content: render_to_string(partial: 'shared/pdf_header') },
               footer: { content: render_to_string(partial: 'shared/pdf_footer') }
      end
    end
  end
end

WickedPDF is a proven solution when you want tight Rails integration and easy use of existing views.

For an in-depth tutorial on WickedPDF configuration and scaling in Rails apps, visit our complete guide.

Grover

Grover Gem Info

Grover is a modern Ruby gem that leverages Puppeteer under the hood, using headless Chrome to render HTML into PDFs. This allows Rails developers to access the latest CSS3, Flexbox, and JavaScript capabilities directly in their PDF output. Grover integrates easily with controllers, Rack middleware, or background jobs.

Example:

# Gemfile
gem 'grover'
# Controller
class ReportsController < ApplicationController
  def show
    html = render_to_string(template: "reports/show", layout: "pdf")
    pdf = Grover.new(html, 
      display_header_footer: true,
      margin: { top: '50px', bottom: '50px', left: '30px', right: '30px' },
      header_template: "<div style='font-size:10px; text-align:center;'>Header Example</div>",
      footer_template: "<div style='font-size:10px; text-align:center;'>Page <span class='pageNumber'></span> of <span class='totalPages'></span></div>"
    ).to_pdf

    send_data pdf, filename: "report.pdf", type: "application/pdf"
  end
end

Grover is ideal for Rails teams that need modern styling capabilities and pixel-perfect output.

For a comprehensive Grover setup with Rails, check our extended usage guide.

Puppeteer-Ruby

Puppeteer-Ruby Gem Info

Puppeteer-Ruby is a direct Ruby port of Google’s Puppeteer library, giving Rails developers fine-grained control of headless Chromium. Unlike Grover, which provides a higher-level wrapper, Puppeteer-Ruby allows developers to script browser actions directly. This is particularly useful for dynamic pages or when simulating user interactions before capturing a PDF.

Example:

# Gemfile
gem 'puppeteer-ruby'
# Script example
require 'puppeteer'

Puppeteer.launch(headless: true) do |browser|
  page = browser.new_page
  page.set_content("<html><body><h1>Invoice</h1><p>Customer details here</p></body></html>")

  page.pdf(path: 'output.pdf', 
           display_header_footer: true,
           margin: { top: '50px', bottom: '50px', left: '30px', right: '30px' },
           header_template: "<div style='font-size:10px; text-align:center;'>Header Example</div>",
           footer_template: "<div style='font-size:10px; text-align:center;'>Page <span class='pageNumber'></span> of <span class='totalPages'></span></div>")
end

Puppeteer-Ruby provides maximum flexibility when developers want raw control over Chromium’s PDF output.

For advanced scenarios with Puppeteer-Ruby in Rails projects, see our detailed implementation article.

Comparison between HTML to PDF libraries in Ruby on Rails

Characteristics

WickedPDF

Grover

Puppeteer-Ruby

Rendering Engine

wkhtmltopdf

Chromium (Headless)

Chromium (Headless)

Output Quality

Moderate

Full (Pixel-perfect)

Full (Pixel-perfect)

Ease of Use

Easy (Rails-focused)

Easy

Moderate

CSS Support

Good (CSS2, partial CSS3)

Full (CSS3, Flexbox)

Full (CSS3, Flexbox)

Community Support

Excellent

Growing

Moderate

Recommended Use

Invoices, simple reports

Modern styled reports, dashboards

Advanced scripting, dynamic content PDFs


Alternative: Convert HTML to PDF at Scale Using pdforge

Homepage of pdforge

Managing HTML to PDF conversion at scale poses challenges, particularly with serverless architectures (see our detailed article) and frequent template updates. pdforge simplifies these challenges by providing a robust PDF Generation API for direct HTML to PDF conversion:

# Controller
class PdfsController < ApplicationController
  def create
    response = HTTParty.post(
      "https://api.pdforge.com/v1/html-to-pdf/sync",
      headers: {
        "Content-Type" => "application/json",
        "Authorization" => "Bearer YOUR_API_KEY"
      },
      body: { html: "<h1>Invoice</h1><p>Customer details here</p>" }.to_json
    )

    if response.code == 200
      send_data response.body,
        filename: "output.pdf",
        type: "application/pdf",
        disposition: "attachment"
    else
      render json: { error: response.body }, status: response.code
    end
  end
end

pdforge also includes a powerful AI Agent that generates PDF templates instantly and a modern no-code editor for quick design fine-tuning. Its intuitive platform allows non-developers to manage templates efficiently. Here's a quick demo on how it works:

You can create your account, experience our no-code builder and create your first layout template without any upfront payment clicking here.

Conclusion

If you prefer an in-house solution, WickedPDF remains the easiest to integrate for classic Rails applications, but Grover and Puppeteer-Ruby provide modern rendering with Chromium for more complex layouts. Among these, Grover strikes the best balance of ease of use and advanced features.

For scaling projects, the complexity of managing multiple templates and high-volume PDF generation makes libraries harder to maintain. In this case, pdforge stands out with its API-first and AI-powered approach, removing the burden of maintaining layouts or infrastructure while ensuring a reliable, scalable, and cost-effective solution for SaaS businesses that want to generate PDFs at scale without worrying about best practices or design overhead.

Generating pdfs at scale can be annoying!

Generating pdfs at scale can be annoying!

Let us help you make it easier while you focus on what truly matters for your company.

Let us help you make it easier while you focus on what truly matters for your company.

7-day free trial

7-day free trial

Table of contents

Automate PDF Generation with pdforge

No code or design experience needed

AI creates your template in seconds

Fine tune the design in our no-code builder

Generate PDFs with our API or integrations