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.
While we’re obviously biased, we created DocRaptor because nothing else could get the job done. DocRaptor uses the Prince PDF engine (more on Prince below) along with some additional JavaScript processing and debugging enhancements. With DocRaptor, you get high-quality PDFs, guaranteed reliability, and advanced features such as complex headers and footers, PDF forms, powerful page break control, complex table support, accessible PDFs, and much more.
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 open-source HTML-to-PDF libraries with the most modern CSS, HTML, and JavaScript support are based on headless Chrome, typically through Google’s Node Puppeteer project. These libraries lack a lot of PDF-specific functionality but allow you to use the latest web technology, like Flexbox, grid layout, and ES6.
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 .pdf
extensions. It provides some options for page size and margins but overall struggles with the same problems of any browser-based system: limited support for complex PDFs, making it difficult or impossible to format long tables, headers and footers, watermarks properly, or create accessible PDFs, just as a few examples.
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.
Historically, most open-source HTML-to-PDF libraries were based on wkhtmltopdf, which uses the Webkit engine. Unfortunately, the version of Webkit that wkhtmltopdf is forced to use is wildly out of date (try these wkhtmltopdf alternatives instead). wkhtmltopdf lacks support for new CSS and JavaScript functionality, including Flexbox. For that reason, we don’t recommend using the below libraries unless you’re writing your HTML/CSS specifically for a PDF and are creating a relatively simple document.
Wicked PDF, created by our good friend and fellow Indianapolis-native Miles Sterrett, is probably the most widely used Ruby HTML-to-PDF library. It has excellent PDF-specific options, including built-in JavaScript delays, table of contents, and grayscaling. It also has a middleware option. Wicked PDF’s only downside is that it’s still based on the outdated Webkit library. A pull request was opened to add a Headless Chrome option, but it doesn’t seem likely to be merged.
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 support@docraptor.com with any follow-up questions. As we discovered many years ago, Ruby PDF generation can be a surprisingly tricky task!