How to make JasperReports groups start on new page only when needed?

Malki picture Malki · Jul 11, 2010 · Viewed 31.5k times · Source

I'm using JasperReports and iReport (output to PDF), and I have a problem with a certain report:

Inside the report I have defined a group. On average, each "instance" of that group only contains a small number of detail rows, so I don't want each of them to start on a new page, since it would be a waste of paper (the output is printed on paper).

But on the other hand, I don't want to have a group that starts on one page and ends on the next one. For example, if on page 1 I can fit the first two groups and half of the third group, I want the entire third group to start on page 2, and so on.

Is there any way to do that?

Answer

Sandeep Sharma picture Sandeep Sharma · Oct 15, 2015

The "group" property keepTogether and isStartNewPage will solve your problem and makes group result together and always starts new group from new page.

<group name="CITY" isStartNewPage="true" keepTogether="true">
  <groupExpression><![CDATA[$F{CITY}]]></groupExpression>
   <groupHeader>
    ...
  </groupHeader>
</group>