Search code examples
jasper-reportspdf-generationexport-to-pdf

Create dynamic PDF starting from jrxml template in JasperReports


I'm trying to generate a PDF with JasperReports starting from a .jrxml template.
The problem is that I'd like to have a sort of dynamic behaviour among the sections of PDF, that are basically subreports. More specifically I need some sections to disappear completely when null (I'm not even sure how to check if a subreport is null) and the other subreports to fill that void moving only upward.

Let me give you an example:
1) Situation where everything is filled
All blocks populated

2) Now the green block is not shown because it's null, and all the blocks below move upward to fill the void left by that section
enter image description here

I don't think I can accomplish this with DynamicJasper am I right?

I really need to start from a .jrxml template created and/or customized by other people.


Solution

  • It is possible with JasperReports. What i recommend is using iReport tool (or some other JasperReport visualizing tool).

    Just like each report, a subreport has a dataSource. When it is null/empty, the subreport should not render. In iReport, utilize the scripting language available (usually Groovy) and do conditional rendering of the Detail band that is hosting your subreport.

    Hope this give you enough pointers to start.