19

Some day ago my boss asked me that he wanted invoices in PDFs from out web application. Given that everybody uses JasperReports and iReport for design I tried it. My web app is based on Java+Hibernate and Spring. At the beginning Jasper seemed fine and iReport too. Anyway I've been stopped by two things:

  • iReport is the slowest thing I've ever seen in my life.
  • More seriously, I've certain beans that have some class hierarchy and it is very complicated to handle this in Jasper. Everybody in my office uses Jasper with SQL queries, and that way it is an easy and handy tool, but I spent my entire day trying to map my beans to reports and subreports and very little works.

I've seen DynamicJasper, but, it seems that I can't design reports with it. What do you think? Are there easier to use alternatives?

Alex K
  • 22,315
  • 19
  • 108
  • 236
gotch4
  • 13,093
  • 29
  • 107
  • 170
  • Are you looking for alternative that will be work in conjunction with Java+Hibernate and Spring? – Alex K Nov 23 '11 at 17:40
  • The DynamicJasper API is the "wrapper" for JasperReports API – Alex K Nov 23 '11 at 17:47
  • 1
    Regarding iReport performance, there is some sort of bug in recent 4.1.x and 4.5 releases. Check out this forum post for more info: http://jasperforge.org/plugins/espforum/view.php?group_id=83&forumid=101&topicid=94781#95291 . Deleting/resetting classpath increased iReport's performance by an order of magnitude for me. – kaliatech Feb 29 '12 at 17:35

2 Answers2

5

If time is of the essence (as is usually the case when your boss hands you something) I would recommend checking out iText (main site is here).

It is very, very simple to learn (you can have it up, running, and generating simple "Hello, PDF!" examples in 20 minutes) and can export just about anything into PDF: tables, lists, charts, images, hypertext, etc.

By my own admission, JasperReports implementing its JRBeanCollectionDataSource is a more elegant, flexible, permanent solution for you. But if you need a quick-n-dirty library to just produce PDFs, and looming deadlines are drawing nigh, I would download the iText JAR and have at it.

The site is loaded with practical code examples for just about anything you would want to accomplish.

Unlike JasperReports, iText is not a report generator. Its just a PDF generator (which, from what I can tell in your question, sounds like all you need). So, for any particular Bean, you would just select the properties you want exported to the PDF invoice, and use the Chunk, Paragraph, etc. classes to append them to the document as you need:

// Your POJO/Bean/VO
Employee oEmp = new Employee();

Document oInvoicePdf = new Document();
PdfWriter.getInstance(document, new FileOutputStream("/invoices/2011/Invoice201.pdf"));
document.open();
document.add(new Chunk("Employee's name is : " + oEmp.getName()));
document.close();

Even if this is not what you're looking for, at all costs I would recommend you steer clear of Apache PdfBox. In my humble opinion, it is pure evil and will only break your heart.

Hope this helps, and best of luck!

IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756
  • I second PDFBox being difficult. It's internal data structures seem to be ridden with memory leaks and aren't really designed to work on large documents. I've ended up needing to close and reopen the source pdf just to clear out all the unnecessary data that it keeps around. I really hope they work out these problems. – Ape-inago Apr 30 '13 at 16:39
  • Is there any new update on this? – powder366 Nov 14 '17 at 18:25
3

As an alternative to iReport you can try JasperWave designer for JasperReports. To address the second issue why not to write some helper java code that translate beans structure to report structure? In any case it is always not easy to map java objects to some kind of flat structure. Create some java interface that will hide the complexity of underlying beans structure. Not sure that the second issue is the the reason to look for alternative reporting solution.