HTML to PDF in Ruby, with headless Chrome and WebDriver BiDi

bidi2pdf is an open-source Ruby gem and command-line tool that turns web pages and HTML into PDFs. It is built for developers, CI pipelines and AI coding agents that need PDF generation they can script: structured JSON results, predictable exit codes and rendering by a real browser.

What it does

Quick start

gem install bidi2pdf
bidi2pdf render --url https://example.com --output example.pdf

Requires Ruby 3.4 or later and Chrome or Chromium – or use the published Docker image.

Common tasks

When to use bidi2pdf

It fits when the PDF should look like the page does in a browser – modern CSS, web fonts, content a script renders, Paged.js print layouts – because Chrome itself renders it; when PDFs are made unattended, in CI, background jobs or by an agent, and a failure has to say what went wrong; and when the code around it is Ruby or Rails, or several processes share one remote Chrome.

Something else fits better when the PDF is drawn in code rather than from HTML – a PDF library does that without a browser – or where neither Chrome nor Docker can run.

For agents and CI

# check compatibility - no browser launched
bidi2pdf version --json

# discover the shape of every result
bidi2pdf schema render

# validate a recipe without a browser, then run it
bidi2pdf run recipe.yml --validate
bidi2pdf run recipe.yml --json

# render with a machine-readable result
bidi2pdf render --url https://example.com --output example.pdf --json
Exit codes
Exit codeMeaning
0success
2CLI, configuration or recipe-validation error
3browser or navigation error
4page not as expected (a recipe action or assertion, or a diagnose selector, failed)
6output or PDF generation failure
70unexpected internal error

Details: structured output, stdin/stdout and progress events, diagnose, recipes. A plain-text summary for language models: llms.txt.

Claude Code plugin

Six skills teach an agent to use bidi2pdf as intended: rendering, recipes, diagnosing a wrong PDF, a shared remote Chrome, review screenshots and PDF specs.

/plugin marketplace add dieter-medium/bidi2pdf
/plugin install bidi2pdf@bidi2pdf

About the skills