Thursday, August 20, 2015

Remove empty space in Jasper Reports

Introduction:

There are many reasons for the empty space in the reports designed in Jasper Studio or iReport. I am tired of finding the reasons and solution for empty space. Hence I am writing this post to target this kind of issues in jasper reports.

Illustrating with a simple report design:

Now let us consider the following report design,


Below are the details of the report

  • Report Height - 180px
  • Title band Height - 100px
  • Summary band Height - 80px
 Details of Title band:
In Title band, the text field components in left side are normal text fields and the text field components in right side are placed inside Frame component.
Details of Summary band:
In Summary band, there are two table component and  some normal text boxes.
  • Both table is of height 20px 
 Print when conditions:
Left side text boxes and right side text boxes displays the same data. There are certain condition  to display each text boxes.

Below image explains the conditions for the text boxes that display "assignment1" value.


If there is a value for assignment1, then text fields displaying assignment1 values will be displayed.

Likewise, there is a condition for the text fields that displays assignment2 values

If there is a value of assignment2, then text fields displaying assignment2 values will be displayed.

Apart from these conditions, each text fields has a property "Remove Line When Blank" is checked

Table components in Summary band displays some percentage values. 

Initial output:

Below is the initial output when there is a data for both assignment1 and assignment2.


The report design looks fine.

Scenarios:

1. Text field inside Frame component and without Frame component

 If there is no data for assignment1, the report design will contain some extra space.

Below is the result of the report, if there is no data for assignment1


When there is no value for assignment1, then there exist a blank space in case of normal text fields. But note that there is no extra blank space for text fields placed within Frame component.

Frame components are much useful in this type of scenario.

If a text fields are displayed based on condition and you want to avoid the extra space, then placing text fields inside the Frame component is a perfect design.

2. Extra space due to table component

There is an another scenario, where extra space may occur due to components like TABLE and LIST.

Let we figure out how these components will result in extra space.

Below is the result of our modified report design.


If you check the design, the Summary band is of height 80px. But the report result has an extra space of height 58px

Below image illustrate the reason for the extra space.


Summary Band Height - Table Component Height = Extra space height
            80px                 -                  20px                =           60px


How to solve this issue? Refer below image


It is just simple,

Summary Band Height - Table Component Height = Extra space height
            80px                 -                  80px                =           0px

which implies,

                         Summary band Height = Table Component Height.

Does it really solve the problem? Refer below image

Conclusion:

  • Extra space might spoil the report design. Avoiding it would make report more real.

1 comment:

  1. Hi, Vignesh, thank you post this article to help us fix some problem,
    I met a problem recently and I want to know if i put more textfield in summary band, I hope it can split to next page correctly, but now I cannot fix it, it always expend more extra space even the data in summary band even though it could be displayed on the first page, but it still expand one blank page to next page, I debug it, and found the summary band extend to next page even though no data, Could you give some idea to help me fix it, thanks. or you can give one simple such as you test case in this article, if the left or right textfield have a long text data in summary band, Can it split the data to next page, I can post some screenshot to you what I debugging data for my problem.

    ReplyDelete