How to prevent page split between details band in JasperReports

jasper-reports

I have a report with two detail bands. First band shows an image, second shows its filename. However, on an occasion, an image would fit into a page in such a way that there is no place left for the text line below. And the filename would go to the next page, which looks quite silly:

  some other contents

     +-------------------+
     |                   |
     |                   |       Page 1
     |                   |
     |                   |
     +-------------------+

  ----------------------------------------------

     foto.jpg                    Page 2

Is there a way to prevent such splits in JR? I.e. I would like page split to occur between records, but not between different detail bands of the same record. In the usecase above, both image and its filename should go to the next page:

  some other contents            Page 1

  ----------------------------------------------

     +-------------------+
     |                   |
     |                   |
     |                   |       Page 2
     |                   |
     +-------------------+
     foto.jpg

Setting split type to "Prevent" on the second detail band doesn't seem to help…

Best Answer

You can add a "dummy" group to your report.

Add a group with a constant expression (like true).

Untick options Add the group header and Add the group footer. You probably don't need those.

Now there are two ways to prevent the split:

  1. Under group options, tick the property called Keep Together. It didn't always work properly in earlier versions of Jasper Reports. Maybe it's better now.
  2. Under group options, there is a property called Min Height To Start New Page. Set its value to the sum of the heights of both detail bands. Then, whenever it will print the group, Jasper Reports will check if the remaining space in the page is greater than or equal to that property. If not, it will print the group on a new page.
Related Topic