PDF generation for Ruby

PDFs that keep their text.

Create precise documents with embedded fonts. Text stays searchable and copyable, and the same input produces the same PDF.

A quarterly report generated by Okab, with searchable text and a blue vector bar chart.
Generated with the report example. Open the PDF.

Everything in the document stays useful.

Build reports, exports, and print-ready pages without turning text into a picture.

Searchable by design

Embed TrueType and supported CFF1 font subsets with ToUnicode mappings, including Japanese text when the font has the glyphs.

Room to compose

Place text and images alongside vector paths, clipping, links, and document outlines.

Predictable output

Generate deterministic PDF 1.7 files without timestamps changing the result.

Start with a font and a page.

Okab requires Ruby 3.2 or newer. Supply a font containing the glyphs you want to render.

Install
gem install okab
Write a PDF
require "okab"

font = Okab::Font.load("report.ttf")
document = Okab::Document.new(title: "Report")
page = document.page(width: 595, height: 842)
page.text("Report", x: 48, y: 790, font: font, size: 24)
document.write("report.pdf")

Coordinates use PDF points and a lower-left origin. Follow the getting started guide for your first document.

Build the next page.

Examples and format notes for each part of your document.

Text and navigation

Choose fonts, wrap paragraphs, add pages, and connect them with links and outlines.

Graphics and images

Draw paths, clip artwork, apply transforms and opacity, and embed PNG or JPEG images.

Check supported formats and limits or see how to contribute.