Authoring · Ruby

Generate a PDF in Ruby

Create PDFs programmatically from Ruby: pages, vector graphics, embedded and subset fonts with full Unicode shaping, justified paragraphs, tables and images. rust-pdf gives Ruby a fast, memory-safe core with deterministic output.

Last updated: 2026-06-29

Why Ruby needs this

Prawn is the usual answer for drawing a PDF in Ruby, and it is good at it, but it has no PDF/A, signatures or AES-256 to grow into. rust-pdf gives you the same authoring surface plus a clean path to those regulated features later, so you do not switch libraries mid-project.

Generation is the free foundation: draw vector shapes, place shaped and kerned Unicode text, lay out wrapping and justified paragraphs, embed JPEG and PNG, and add links and bookmarks. Output is deterministic, so the same input always yields the same bytes, which makes it auditable and testable.

Build the document in a Rails controller or a Sidekiq worker with Document.new and a chained add_page, then stream the bytes back; the gem loads its native core over Fiddle from the standard library, so there is no heavy runtime and no wkhtmltopdf process to babysit.

  • Vector graphics, embedded and subset fonts, HarfBuzz-quality Unicode shaping and kerning.
  • Wrapping and justified paragraphs, tables, images (JPEG, PNG, alpha, 16-bit).
  • Deterministic output: identical bytes for identical input, ideal for audits and tests.

Generate a PDF in Ruby with rust-pdf

Install with RubyGems, then call the same idiomatic API every rust-pdf binding shares. The snippet below is real Ruby code from the reference docs.

gem install rustpdf

Ruby
require "rustpdf"

doc = RustPdf::Document.new          # A4 by default
doc.add_page
   .fill_rgb(0.86, 0.20, 0.18)
   .rect(72, 640, 200, 120)          # x, y, width, height (points)
   .fill
doc.save("out.pdf")
doc.close
Validated by: qpdfmutool

This is part of the free tier in Ruby. No license required.

Full Ruby reference in the documentation.

Generation in Ruby: FAQ

Is generating PDFs free in Ruby?

Yes. All basic generation (pages, graphics, fonts, text, paragraphs, images, links, bookmarks, watermarks) is free forever. You only license corporate features such as PDF/A, signatures and encryption when you ship them.

Does it support Unicode and custom fonts?

Yes. Fonts are embedded and subset with HarfBuzz-quality shaping and kerning, using Type0 fonts with ToUnicode, so non-Latin scripts render and extract correctly.

Why a Rust core for Ruby?

One memory-safe, high-performance Rust core is exposed to Ruby through a thin idiomatic binding. You get the same engine, the same features and deterministic output, without a heavy runtime.

How do I return a generated PDF from a Rails controller?

Build the document with Document.new in the action or a Sidekiq worker, then send the saved bytes with send_data and an application/pdf content type. The gem loads over Fiddle, so there is no wkhtmltopdf process to manage and the output stays deterministic.

Start building PDFs in Ruby today

One Rust core, the same output across every language. Prototype for free, license the corporate features when you ship.