Creating dynamic reports with JasperReports


In my current project we have a requirement that is frequently discussed in the Jasper community. How do I create a dynamic report in JasperReports? The complex detail is that we need to create one pdf with a unknown number of pages with totally different pagehights.

The requirements are :

1. Dynamic JasperReports template that is completely dynamic with a dynamic content.
2. It has a unknown number of pages with different pageheights.  Jasper have no out of the box support for Requirement 2, so how did we solve this?


To solve this issue we have to use an exernal library iText. Create the jasper template that is needed with no pagebreak. Then generate each page as a seperate report and use iText to merge all the pages. There you go, it’s done!

This is how it is done:

1. Create a template jr1.jasper with “ignore pagination” set, this will make sure that all information will be on one large page in the generated report.

2. For each report from the input source(xml or database), generate a pdf based on the jr1.jasper template and store it in a list or cache it on disk. When all the items are genereated from the input source you will have a list with a number pdf documents..

3. Use PdfCopy in the iText library to merge the generated pdf:s into one large pdf. (Link to code example pdfmerger).

This makes it possible to have different pagesizes in one pdf concatenated.pdf.


Git repository to complete project –

Please refer to this readme file for more instructions on how to run the project README.

Leave a Reply