Install the Ruby gem
Add the package to your application:
bundle add ironpress
Or install it globally:
gem install ironpress
Releases include native gems for supported Linux, macOS, and Windows targets, plus a source gem.
Create an HTML PDF
The module function returns a binary Ruby String containing the complete PDF:
require "ironpress"
html = <<~HTML
<style>
@page { size: A4; margin: 18mm; }
h1 { color: #295dff; }
</style>
<h1>Hello from Ruby</h1>
HTML
pdf = Ironpress.html_to_pdf(html)
File.binwrite("output.pdf", pdf)
Keep the string in binary form and send it as application/pdf or write it with File.binwrite.
Render Markdown
pdf = Ironpress.markdown_to_pdf(
"# Release notes\n\nEverything shipped."
)
File.binwrite("release-notes.pdf", pdf)
Build a reusable policy
Each configuration call returns a new converter value, so settings compose naturally in a chain:
converter = Ironpress::HtmlConverter.new
.page_size("Letter")
.margin_sides(36, 48, 36, 48)
.header("Quarterly report")
.footer("Page {page} of {pages}")
pdf = converter.convert("<h1>Results</h1>")
markdown_pdf = converter.convert_markdown("# Results")
Use convert_to_file or convert_markdown_to_file for direct file output.
Load local resources and fonts
Grant a resource boundary, then pass custom font data as a binary string:
converter = Ironpress::HtmlConverter.new
.base_path("templates")
.resource_root(".")
.add_font("Inter", File.binread("assets/Inter.ttf"))
pdf = converter.convert(<<~HTML)
<style>body { font-family: Inter }</style>
<img src="assets/logo.png">
HTML
Optional CJK and emoji font packs also enter as caller-provided bytes. The renderer never downloads them.
Handle failures and runtime limits
Invalid named settings raise ArgumentError. Conversion failures raise RuntimeError, while file operations keep Ruby's normal I/O errors.
- HTML sanitization is enabled by default.
- The Ruby binding has no async or streaming conversion API.
- Remote HTTP document resources are not available from the gem.
- Use a browser renderer for JavaScript-driven pages or exact Chrome output.