PDF Generation Library for Java

41,482

Solution 1

Give JasperReports a try. Use iReport to create the .jrxml files. JapserReports can handle complex layouts. For those parts of the report based on different queries have a look at using subreports embedded into the main report.

Just like @Adrian Smith's solution this approach will separate the report layout editing from the data sourcing.

Solution 2

I have implemented a good solution where my software creates a format-independent "pure" XML file, then I give my boss the XSD and he puts it into Altova StyleVision where he can WYSIWYG design reports based on data he plucks out from the XSD. That software produces an XSLT. So my program:

  • Produces the format-independent "pure" XML
  • Transforms it with the XSLT, the output of which is XML-FO
  • Use Apache FOP to convert the XML-FO into PDF

This is a really great solution, means no more do I (as a programmer) have to change my code each time my boss wants to change a color in the report, my job is simply to produce "pure" XML.

Update: I should also point out that I give my boss access to our SVN repository with Tortoise SVN which is sufficiently easy to use that he can use it without error. So he can check the XSLT files straight into SVN and run the build/deploy without even having to interrupt me from my work. Obviously that workflow only works with people who are sufficiently exact that they don't make mistakes etc., but it works out well for us in that case.

Solution 3

Based on my experience, I would suggest you to consider following Java PDF Libraries for creating PDF reports,

  1. DynamicReports
  2. Apache PDF Box
  3. iText PDF
  4. PDF Clown

For your requirement, I think DynamicReports would be the right choice. I have been using Dynamic Reports from last 3 years for all my PDF Reporting requirements. With a very less amount of code, you can easily create a truly dynamic PDF. Dynamicreports is a wrapper around Jasper Report. So, it internally makes use of Jasper report.

Solution 4

Docmosis allows you to create templates in Word or OpenOffice writer - separating concerns nicely and layout is then in the most familiar tools.

Solution 5

I have been using JODConverter for a while and I really like it.

What we do is use JODReports to generate dynamic OpenOffice.org documents (which internally uses FreeMarker). Then we convert these documents to PDF documents using JODConverter.

It sounds like a lot of work, but it really isn't.

Share:
41,482
Stefan Haberl
Author by

Stefan Haberl

Freelance coder passionate about all things code. I’m a senior software craftsman enthusiastic about creating lean and elegant code. I have more than 20 years of experience as a full stack dev working within the Web and Java eco systems and am an advocate of all things that make a developer’s life easier. If I’m not busy coding, you can find me roaming the peaks of the Austrian alps or travelling the world. I’m also always more than happy to chat about photography over a glass of good red wine. As freelancer I’m always on the lookout for exciting new projects. Drop me a line and let’s start talking!

Updated on January 02, 2020

Comments

  • Stefan Haberl
    Stefan Haberl over 4 years

    I know this has been asked before, but I'm still undecided on which PDF generation framework to use for my current project.

    My requirements

    • on-the-fly generation of PDF documents (mainly order forms, invoices)
    • Java based
    • easy to layout
    • should be open source
    • easy to change layout

    A lot of people seem to use iText, but I have some concerns (apart from the changed licence) regarding separation of concerns: In an HTML context there's good MVC support, where I usually stick to Spring MVC and FreeMarker to separate logic and layout. I'm a little bit worried that with iText you end up mixing code and layout a lot.

    I am aware, that Apache FOP could be a solution here, but then again I find XSLT tedious to work with and I read that FOP can be slow when it comes to huge throuput of many documents?

    I also considered JasperReports, but from my understanding this is more suited for reports containing tabular datasets rather than single documents such as invoices which require a lot of layout formatting?

    Any thoughts on this?

  • Adrian Smith
    Adrian Smith over 13 years
    +1 That looks like a good product too!
  • Stefan Haberl
    Stefan Haberl over 13 years
    Thanks Janek, I think I'll prototype using Jasper
  • Stefan Haberl
    Stefan Haberl over 9 years
    Just in case anybody from the future is stumbling across this old thread: Use JasperSoft Studio now instead of iReport.
  • JFreeman
    JFreeman over 5 years
    It looks like the link to DynamicReports is dead
  • Prasanna L M
    Prasanna L M over 5 years
    I have updated the link. The original website on which Dynamic Reports was hosted is no longer available. The link is down from the last couple of months. Now, few members from the community are maintaining this project.
  • artbristol
    artbristol over 4 years
    JasperReports is a heavyweight reporting application. It does PDFs, but integrating it into another application is a complicated affair (I'm speaking from experience). I'd choose something simpler, preferably a library.