How to Generate PDF from HTML in Java Using Flying Saucer
Looking for a reliable way to convert HTML to PDF in Java – without relying on headless browsers or heavyweight libraries? In this tutorial, you'll learn how to use Flying Saucer (xhtmlrenderer) together with Thymeleaf templates to generate clean, professional PDFs directly in your Java application. Flying Saucer is a lightweight, pure Java library that renders XHTML and CSS into PDF format – no external rendering engines required. It’s ideal for reports, invoices, and other dynamic documents where fast and reliable PDF generation is essential.
What is Flying Saucer?
Flying Saucer (also known as xhtmlrenderer) is a pure Java library designed to render well-formed XML/XHTML and CSS for display and printing. Unlike browser-based PDF generation tools, Flying Saucer offers a lightweight, server-friendly approach for PDF generation.
Originally developed as an open-source project, Flying Saucer has been widely adopted in enterprise Java applications where consistent PDF output and low resource consumption are critical.
Flying Saucer is released under LGPL v2.1 or later, which permits its use in both open-source and commercial projects, provided you comply with the license terms.
For full details, see the LICENSE file on GitHub.