• josh.earth
  • ← All projects

    Flying Saucer

    An open source 100% Java XHTML and CSS renderer for desktop apps and print

    Personal · 2004

    The idea

    Flying Saucer was/is an open source pure Java HTML renderer. I started Flying Saucer in 2004 because Swing's built-in HTML support was too limited what I wanted to do. I needed to put real CSS styled web-like content inside Java applications. To keep the scope feasible by a solo developer (this was 2004, after all) I focused on well-formed XHTML and XML with CSS, with no JavaScript or other browserish features.

    The first version rendered basic web content in a scrolling Swing JPanel with support for the CSS box model, tables, images, and partial positioning support. I put it up on Java.net as an open source project, but didn't expect anyone other than myself to be interested. How wrong I was.

    Flying Saucer's demo browser rendering its project splash page
    The Flying Saucer splash page rendered in its demo browser.

    While I led the project

    Over the next few years, with big help from some open source contributors, we improved the renderer and eventually had near-complete CSS 2.1 support, including floats, tables, and pagination, along with a faster, more standards-compliant CSS parser. If you used an HTML-to-XHTML cleanup library like JTidy, it could render some existing sites, though without JavaScript, of course.

    Flying Saucer grew beyond its original Swing GUI use case. It turns out lots of people wanted to render documents as PDFs, but found XHTML and CSS a lot easier to work with than native PDF APIs. In a 2007 article, I showed how to use Flying Saucer with iText to render paginated PDFs with headers, footers, and page numbers. The Alice in Wonderland PDF preview below is an example of that print workflow.

    First page of an eight-page Alice's Adventures in Wonderland PDF rendered with Flying Saucer
    Page 1 of 8 from the Alice sample PDF. Click the preview to open the full PDF.

    After my handoff

    By the R7 release, Peter Brant had made major code contributions and Patrick Wright had taken over as project leader while I moved on to other work. By that point I had joined Sun Microsystems, moved across the country, and gotten married. The project continued on, led by the community. It eventually even got its own Wikipedia page!

    The CSS Zen Garden Icicle design rendered in Flying Saucer's demo browser
    The CSS Zen Garden Icicle design, included in the project's screenshot gallery.