PDF Generation Library for Java

Stefan Haberl picture Stefan Haberl · Oct 21, 2010 · Viewed 37.7k times · Source

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?

Answer

Janek Bogucki picture Janek Bogucki · Oct 21, 2010

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.