DocRaptor HTML TO PDF API

Top Java HTML-to-PDF Conversion Libraries

This article reviews the top HTML-to-PDF Java libraries and a few non-HTML-based conversion libraries, too. We’ll rely on our decade of experience in PDF conversion and point out the relative strengths and weaknesses of the various libraries. However, as some of these libraries are either out of date or otherwise unsuitable, we haven’t used all of them in production. Therefore, please use this guide only as a starting point for your own research.

We built DocRaptor in 2010 because we couldn’t find a good HTML-to-PDF converter. We still believe it’s the best overall Java HTML-to-PDF option, but that doesn’t mean it’s the best option for every Java project. PDFs can be surprisingly complex, and the requirements for each vary massively.

Before you evaluate the various libraries, we’d recommend considering the following dimensions of your project:

With that in mind, on to the list!

DocRaptor HTML-to-PDF API

Yes, we’re biased, but DocRaptor is awesome and easy to use! We use the Prince (more on Prince in a minute) engine for PDF generation, combined with some additional JavaScript and support tools. Prince is the most powerful HTML-to-PDF generator and enables you to easily create PDFs with complex headers, PDF forms, footnotes, mixed layout and sizes, accessible PDF tags, finely-tuned page breaks, printer’s marks, and more. We also support advanced CSS functionality, such as Flexbox, and JavaScript, unlike many alternatives.

You can sign up for a free DocRaptor plan and be up and running in minutes with our Java HTML-to-PDF agent. You can even try it without an account via our public, testing API key. Paid plans start at just $15/month, and we provide unlimited test documents.

Prince

PrinceXML is a pioneer in HTML-to-PDF conversion. Their team wrote the CSS Paged Media specifications that enable much of DocRaptor and Prince’s unique conversion capabilities. Additionally, the inventor of CSS and CTO of Opera, Håkon Wium Lie, is chairman of the company.

Unlike DocRaptor’s usage-based pricing model, Prince relies on upfront licensing. Licenses start at $2,000. While the core of Prince is written in Mercury, Prince does offer a Java wrapper.

iText

iText is the most popular commercial HTML-to-PDF Java library. The iText Core library lets you create and modify PDF documents, while the pdfHTML add-on provides support for HTML-to-PDF functionality. iText sells a number of other add-ons as well. Overall, iText is an extremely powerful PDF creation and manipulation library with capabilities far beyond HTML-to-PDF conversion.

It’s difficult to compare just the HTML-to-PDF functionality, as iText doesn’t provide a list of supported HTML elements and CSS properties. iText does not support JavaScript; iText cannot use CSS to define common document elements such as headers, footers, or footnotes. These elements must be created by writing custom Java methods. On the plus side, iText does allow you to expand its HTML parsing by defining custom HTML elements.

iText pricing varies depending on your usage type and volume. You’ll need to talk to a sales representative to get exact pricing information.

Open HTML-to-PDF

An open-source library, based on Flying Saucer and the Apache PDFBox project. It lacks support for JavaScript, CSS Flexbox, and OpenType fonts. It does support part of the CSS Paged Media specifications and is actively working on others, such as footnotes.

In general, Open HTML-to-PDF appears to be well-featured, but has a lot of bugs and difficult edge cases. The README suggests using table layouts and writing HTML specifically for this library. For those reasons, we’d recommend Open HTML-to-PDF only for relatively simple PDF documents and with HTML built specifically for Open HTML-to-PDF.

Aspose

Unlike iText, which is focused on PDF management, Aspose focuses on file conversion across many different file types. Their Aspose.HTML product can convert HTML into a PDF or almost any other format. Aspose.HTML supports HTML, CSS3, and JavaScript conversion.

While Aspose.HTML does not support the CSS Paged Media specifications, it does offer minimal support for custom CSS extensions that provide page numbers (but not headers, footers, footnotes, etc). Headers and footers can be created by using the Aspose.PDF product to edit the PDF document, just not through the HTML and CSS directly.

In general, Aspose.HTML seems like a good option for basic HTML document conversion but isn’t suited for more complex PDF-specific functionality. That requires custom coding with the Aspose.PDF product.

Aspose products are available via a usage-based API or with a license. Licenses start at $999 for a single developer.

Java wkhtmltopdf Wrapper

Historically, wkhtmltopdf was one of the most common HTML-to-PDF tools. Unfortunately, it's based on an ancient version of the Webkit browser and is way out of date. If you need modern CSS and JavaScript support, do not use wkhtmltopdf (we have a list of wkhtmltopdf alternatives).

PDFreactor

PDFreactor is a commercial HTML-to-PDF generator, very similar to Prince. It provides high-quality PDFs with support for JavaScript, CSS Flexbox, and Grid Layout. It also supports PDF forms. PDFreactor is well regarded in the industry, and pricing starts at $2,950 per CPU with a free non-commercial option.

Non-Java Options

There are several additional options available if you look outside of the Java community. For a complete list, look at Node.js HTML-to-PDF generators, PHP HTML-to-PDF libraries, Python HTML-to-PDF converters, or Ruby HTML-to-PDF libraries. The two top DocRaptor alternatives are probably:

Puppeteer

Puppeteer is a Node-based Headless Chromium maintained by Google. While Chromium has very limited support for advanced PDF-specific functionality, it obviously has the most complete support for modern CSS and JavaScript. It’s a good fit for simple PDFs generated through single-page applications or complex JavaScript-heavy websites.

WeasyPrint

WeasyPrint is a Python library that focuses solely on HTML-to-PDF conversion. It provides excellent support for PDF-related functionality but has a reputation for being slow. It does not support JavaScript, only HTML and CSS. It can be a good option for a PDF with some complexity, but with simple CSS requirements.

Selecting a Library

We began this article with some of the dimensions to consider when evaluating Java HTML-to-PDF libraries. As you narrow down your options and begin testing, consider some of these comparison criteria, as well:

We hope this guide has been a helpful starting point for your Java HTML-to-PDF library research. If you have any feedback or suggestions, contact us at support@docraptor.com.

Ready to get started? Try DocRaptor for free with unlimited test documents.