Skip to content

Generate PDF invoices in Ruby without a headless browser

Native PDF compilation for Rails, Sinatra, or any Ruby service. Design documents as Typst templates, pass JSON, and get typeset PDFs back in milliseconds.

Ruby apps generating PDFs usually wrap the abandoned wkhtmltopdf through wicked_pdf or PDFKit, drive headless Chrome through Grover, or write every layout as code with Prawn.

Oicana compiles PDFs in process through a native library instead. Install with bundle add oicana, load a packed template once, and compile documents from JSON:

require "oicana"
template = Oicana::Template.new(File.binread("invoice-0.1.0.zip"))
pdf = template.export_pdf(
json_inputs: {
"invoice" => { number: "2026-001", customer: "Acme GmbH", total: "€1,190.00" },
},
)

A warmed up template produces a typeset PDF in single digit milliseconds, directly in your application.

The snippet loads invoice-0.1.0.zip, a packed Oicana template. Templates are plain Typst projects: a typst.toml manifest declares a JSON input named invoice, and main.typ uses it:

typst.toml
[package]
name = "invoice"
version = "0.1.0"
entrypoint = "main.typ"
[tool.oicana]
manifest_version = 1
[[tool.oicana.inputs]]
type = "json"
key = "invoice"
development = "invoice.json"

The development value points at a JSON file in the template that stands in for real data while you design the template. It is also what the warm-up compilation during registration uses by default.

invoice.json
{
"number": "2026-42",
"customer": "Acme GmbH",
"total": "€42.00"
}
main.typ
#import "@preview/oicana:0.2.1": setup
#let read-project-file(path) = read(path, encoding: none)
#let (input, oicana-image, oicana-config) = setup(read-project-file)
#set document(date: datetime.today())
= Invoice #input.invoice.number
Billed to: #input.invoice.customer
*Total: #input.invoice.total*

Running oicana pack in the template directory produces the zip. Create a Template walks through the manifest and input definitions, and the open source example templates include a complete invoice.

Create a template once per process and compile per request. A Template is safe to use from multiple threads, and Oicana releases the GVL while it compiles, so Puma’s other threads keep serving requests in the meantime. Compilations of the same instance serialize internally, so for more concurrency under heavy load, create several Template instances from the same template file.

Oicana cannot compile in a process forked after its parent compiled. With forking servers and job runners like Puma in cluster mode or Solid Queue, create templates on first use instead of during boot, so every worker gets its own.

The Rails example project shows a complete application.

No headless browser

Platform gems bring a native library that compiles PDFs inside your Ruby process. No wkhtmltopdf binary to maintain, no Chrome for Grover to drive.

Your data stays with you

Documents are generated inside your own application. No customer data is sent to a third party, which keeps GDPR and HIPAA compliance in your hands.

Flat price, unlimited documents

One flat license per application, no metering. A hundred invoices a month cost the same as a hundred thousand. Non-commercial use is free.