We’ve loved Ruby for years. We built DocRaptor on Ruby on Rails over a decade ago when we couldn’t find any Ruby PDF generators that could meet our needs.
While we still believe DocRaptor is the best PDF generation tool (you can get started in minutes with our Ruby HTML-to-PDF agent), it’s not necessarily the best option for every Ruby project.
Below is our list of the top Ruby conversion tools. We’ll outline some key strengths and weaknesses, but we haven’t used these tools in a production environment, so we urge you to do your own research and find the ideal fit for your needs.
There are a few different categories of PDF generators. At the high-end of the market, there are commercial generators (like DocRaptor). These have the highest cost but offer features and generation capabilities that are not available in open-source libraries. There are also browser-based HTML-to-PDF libraries, based on either Google Chromium or Apple Webkit. Lastly, there are some non-HTML-based libraries.
PDF creation is largely driven by large enterprises with legal requirements or complex publishing needs. For that reason, the commercial generators tend to offer the best support for creating advanced PDFs. If you need to create more than a simple one-page report, we’d recommend starting your research with one of the below tools.
DocRaptor is an online HTML-to-PDF API. We have a small free plan with larger plans starting at $15/mo or $0.25/document. As you can see from our testimonials page, we’re trusted by some of the largest organizations in the world.
The Prince library, previously named PrinceXML, is the backbone of the DocRaptor service. Prince pioneered the HTML-to-PDF technology, and Håkon Wium Lie, the inventor of CSS and CTO of Opera, serves as Chairman of the company. They wrote the CSS Paged Media specifications that enable a large percentage of PDF-related functionality. We highly recommend Prince for anyone who doesn’t want to use an external API. A third-party wrapper, Princely, is available for Ruby, and pricing starts at $2,500/year.
The Grover gem uses Puppeteer to convert your Ruby web pages into PDFs (or images). It can even be configured as middleware to automatically extend your URLs with
Puppeteer-ruby is a port of Puppeteer to Ruby. It covers most, though not yet all, of Puppeteer’s APIs. If you need to do advanced page-level manipulation (perhaps if you’re relying on third-party HTML?), Puppeteer-ruby might provide some advantages over Grover. Still, Grover is likely the easier and better option for most applications.
PDFKit is another popular Webkit-based library. While it also has a middleware option, it lacks many PDF-related features that Wicked PDF has added. For that reason, we’d recommend looking at Wicked PDF first.
Unlike the previous HTML-to-PDF tools, Prawn functions more like a DSL and allows you to create a PDF element-by-element, line-by-line. Because of this, Prawn offers more advanced PDF creation functionality than the open-source HTML-to-PDF libraries. The downside, in our opinion, is that creating a PDF line-by-line is far slower than creating an HTML and CSS document. Obviously, that depends on the particular document and developer. Prawn is a fast generator and has been historically very popular, though its maintainer currently considers Prawn to be feature complete so future upgrades are unlikely.
HexaPDF is a complete PDF manipulation library, including creating, editing, merging, and more. It is very powerful overall, though PDF creation is its weakest area. It doesn’t yet include support for tables, for example. But if your needs revolve more around manipulation and creation, it’s likely an excellent library for you and is, unlike Prawn, is still under active development.
The downside is that HexaPDF is under the AGPL license. Commercial licenses start at €500/year but non-commercial usage is completely free.
If you’re willing to look beyond Ruby, we’d also recommend Python-based, open-source Weasyprint. Like other open source PDF generators, it doesn’t have as much functionality as DocRaptor or other commercial tools, but it’s the most full-featured open-source library we’ve seen, and it’s in very active development. If you need more than a basic PDF and have a limited budget, Weasyprint may be your best option.
While DocRaptor is the only API based on a commercial engine, there are numerous other APIs available. HTML2PDFRocket is a popular choice. All these online APIs are based on the aforementioned open-source HTML-to-PDF libraries, either Headless Chrome or wkhtmltopdf. As such, they suffer the same weaknesses. They have excellent HTML and CSS support (at least for Headless Chrome) but poor PDF support, making these APIs only usable for simple documents.
There are many good options for generating PDFs with Ruby. Your decision will likely depend on the complexity of your document and the size of your budget. The commercial tools, like DocRaptor, will provide superior capabilities and better support, resulting in a faster development time and, typically, less maintenance. Factors that affect document complexity include:
Scalability is another major concern if you need to generate a high volume of PDFs. PDF rendering is a higher-resource task than most web server tasks and requires several seconds or more for complex PDFs. This is typically supported via background jobs and/or Lambda workers, but it’s not as simple as installing a gem and moving on. DocRaptor’s instant scale and reliability are a big advantage in this scenario.
We hope this list has helped you narrow down your options. Feel free to contact us at firstname.lastname@example.org with any follow-up questions. As we discovered many years ago, Ruby PDF generation can be a surprisingly tricky task!