Skip to content
RY

Backend / Tooling · 2014

htmlToPdf

A Ruby gem that converts HTML and CSS into PDF documents suitable for invoices, receipts, and reports, designed to behave predictably under production load rather than as a thin wrapper around a headless browser.

RubywkhtmltopdfRSpec

The problem

Generating PDFs at request time in a web application is easy to get working and easy to get wrong under load — render processes can hang, leak memory, or silently produce malformed output for edge-case markup like multi-page tables.

The solution

Wrapped PDF rendering in a supervised subprocess with strict timeouts and memory limits, added template helpers for common invoice/report layouts, and built a test suite that renders a fixed set of templates and diffs output byte-for-byte to catch rendering regressions.

Architecture

Each render request forks an isolated renderer process with a hard timeout; failures return a typed error instead of a hung request. A thin caching layer memoizes repeated template compilations.

Results

  • Used in production to generate customer-facing invoices at scale
  • Eliminated hung render processes that previously required manual intervention
  • Render regressions caught in CI via byte-level output diffing