Jump to content

Paging when adding variable number of subreports


dcoales

Recommended Posts

Hi,

 

I have an application where the user can select a variable number of charts to view on screen (in a browser) and then ask for the charts selected to be printed to pdf.

 

To achieve this I use the jasper api library to programatically create an outer report with only the title, details and pageFooter sections included and sized to fill an A4 sheet and then go into a loop creating each selected chart as a subreport and adding the subreport to the outer report.

 

Initially I didn't set x and y positions for each subreport and so all the reports unsurprisingly sat on top of each other. I then tried incrementing y each time by the size of the previous report but quickly got an error message saying that y + element height exceeded the band height.

 

Interestingly if I didn't specify a height for the sub report at all it worked fine for the first element whose bottom edge would be off the page; I guess because the y position plus an element height of 0 was still less than the band height. In this case a new page was thrown and the subreport started at the top of the next page.

 

Unfortunately the next report had a y position which was already greater than the band height before trying to add any element height and this caused an error message again.

 

Is there an easy way to tell jasper to throw a page if the y position is greater than the band height or do I have to catch this, throw a page break myself and adjust the y position to something appropriate for the new page ?

 

Any help gratefully received.

 

Thanks in advance

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi,

Instead of trying to calculate the "y" position, you can set sub-reports with the Position Type to "Float", flag the "Remove line when blank" and set up a "Print when expression" that evaluate the choosed options.

 

I work with IReport though, so I can't be really precise on how to implement it into your application.

 

I hope it sends you into the right track.

 

Gan

Link to comment
Share on other sites

Hi,

 

Thanks very much for your suggestion. I have tried that but if I don't set any y values and set the position_type to float then the subreports are just placed on top of each other. According to the manual, element e2 will float below element e1 if:

 

e2 has postitionType="Float"

e1.y + e1.height <= e2.y

e1.width + e2.width > max(e1.x + e1.width, e2.x + e2.width) – min(e1.x, e2.x)

 

I have to admit I don't really understand the above. Getting the subreports to float is really what I'm after but I don't know which combination of settings to apply to the subreport to make this happen.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...