How to make the report engine adjust band height to fit the real space occupied by content?

0

I have couple of lines of text that must be printed above the <detail> section (i.e. under the regular <title> and <pageHearder> section) and only on the first page. My currently solution is to place the text as the bottom part of the <pageHearder> and use printWhenExpression(PAGE_NUMBER = 1) to make them only appear on the first page. This solution works fine for the first page but the problem is that for the rest of pages the space that is reserved for the text become an ugly blank block. Is there some way to make the report engine dynamically and automatically adjust the height of a band to eliminate the blank blocks when not all its contents get printed? Or there are other ways to solve problem? I searched the web and found this post http://efreedom.com/Question/1-2884089/Use-Jasper-Reports-Print-Something-First-Page asked almost exactly the same question as mine but the solution in its reply does not work.
 
sunnyramon's picture
Joined: Nov 30 2010 - 8:52pm
Last seen: 8 years 3 months ago

5 Answers:

0

If the report is a single-column layout (ie. columnCount = 1), you could use the <columnHeader/> section for those couple of lines only.

HTH,

sanda

Code:
<pageHeader>
 the_regular_page_header_content_here
</pageHeader>
<columnHeader>
 <band height="<your_couple_of_lines_of_text_height>">
 <printWhenExpression><![CDATA[$V{PAGE_NUMBER} < 2]]></printWhenExpression>
 the_conditional_header_content_here
 </band>
</columnHeader>


Post Edited by shertage at 02/07/2011 19:14
shertage's picture
1892
Joined: Sep 26 2006 - 8:06pm
Last seen: 1 day 20 hours ago
0

Sanda,
Thanks for your suggestion. Unfortunately my report has multiple columns.
I don't understand why jasper uses so static band height. If it could support something like height="*" to indicate the height is as mush as needed that would be great.



Post Edited by sunnyramon at 02/07/2011 19:26
sunnyramon's picture
Joined: Nov 30 2010 - 8:52pm
Last seen: 8 years 3 months ago
1

Yes, dynamic values for attributes are still a problem, indeed. But not the variable band height. It can be solved with stretch attributes.

  1. ensure that splitType attribute of the pageHeader is set to "Stretch"
  2. put all text that needs to be printed on the first page only in one or more textfields having  isStretchWithOverflow="true", and height="1" (this height will be dinamically increased at fill time)
  3. for textfields at point 2, write the printWhenExpression too
  4. calculate your pageHeader band height considering that the textfields at point 2 have exactly height="1"

I think that this should solve the problem.

Please also to consult the stretch sample in order to find out more about how to combine a series of stretch attributes in order to get the optimum report layout.

HTH,

sanda

 



Post Edited by shertage at 02/07/2011 20:50
shertage's picture
1892
Joined: Sep 26 2006 - 8:06pm
Last seen: 1 day 20 hours ago

Hi Sanda,
please help me, I do not understand your solution.
What this solution works well in <detail>...</detail>
Thanks

baim - 5 years 9 months ago
0

Sanda,

Your solution works great. Thanks a lot.

Sunny



Post Edited by sunnyramon at 02/08/2011 22:53
sunnyramon's picture
Joined: Nov 30 2010 - 8:52pm
Last seen: 8 years 3 months ago
0

Thanks.

It works fine if you want to adjust the <pageHeader> but doesn't work in the <columnFooter> or <pageFooter>.

Are there any solution¿?

pedrera_j's picture
Joined: Jun 21 2012 - 9:01am
Last seen: 6 years 9 months ago
Feedback
randomness