iReport Designer - dynamic list and page number - jasper-reports

I have put a list inside a rectangle with Relative to Tallest Object property which is inside a frame with Float property. All the components are inside the detail band. The size of the list component depends on the list which is sent from my Java application.
When I print a report with 100 objects inside a list, all records are not printed inside a rectangle. I don not know how I can fix it. Just the first page has a rectangle.
Also, I have a problem with page number. I put the page number variable at the bottom of the detail band with maximum height, but it is printed just on the first page. On other pages there is no any page number.
It would great if someone can help me.

Related

Detail band resize dynamically vertically when textfield is NULL

I have a JasperReports report build with iReport. I have the normal Detail band but below i have a textField named observations there is sometimes the Observations textField is empty or NULL. I have put both inner components namely textfields, lines into frames something like.
I also set using Print When Expression the below frame the one who holds the Observations textField to appear only when there is data on it this is working very good but the space holds by the frame is still on the Detail and we are losing some space and it's kind annoyng to see this blank space.
Is it possible for the report to "delete" the idle space hold it by the hidden frame?
My report's design:
The generated result (PDF file):
I don't think it's possible to alter the height of a band depending on its content but you can actually have multiple detail bands. So add a new one, move your observation text field into it and set the print when expression of the second band.

How to fix the number of rows while designing pdf using iText in java

I am creating one pdf file showing a list of all employees and their salaries. At the end of the page it is showing the total of all salaries.
I am using a for loop to add multiple rows to table.
The problem is:
at the end the row, the total salary doesn't fit on the same page and it is shown on the next page.
So is there any way that I can calculate the height of the page and then fix the height of each cell? And then accordingly, limit the number of rows.
So that at the end of the page, I can show the total number of rows and further record from next page.
Calculate the height of the page: well... you decide on the size of the page when you create a Document object. You can choose any size you want.
Calculate the height of a PdfPTable: that's explained in chapter 4 of my book. When you create a PdfPTable, you add PdfPCell objects to an object that only exists in memory and that doesn't know anything about page size. By default, the width is expressed as a percentage of the available width of the page to which you'll add the PdfPTable. Only when you add the PdfPTable to a specific Document, the exact width and the height will be calculated (which is too late for you).
If you want to know the height in advance, you need to define an absolute width (not a percentage). Tables with the same content and a different width will have a different height. Defining an absolute width is done like this:
table.setTotalWidth(width);
table.setLockedWidth(true);
In this snippet (taken from the TableHeight example), width equals the width of the page minus the left and right margin. You're defining the width of the page and the margins upon creation of the Document object. By default, the page size is A4, so the default width is 595 user units and the default margins are 36 user units.
So, one way to solve your problem, would be to add rows in a loop and calculate the height of each row with the getRowHeight() method or the height of the complete table with the getTotalHeight() method (both methods will return 0 if you omit setting the total height). If you see there's not enough space to add the summary row, you can use the deleteLastRow() method to remove that last row and to create it anew in a new table on the next page.
That's one solution. Another solution could be to use table and cell events, but that's more difficult to explain.

Dynamic page height to show 10 records per page with StretchWithOverflow property set to true

I have 10 records per page (9 columns) in jasper using page break property. I have set StretchWithOverflow property to true for my detail band. So, when there is more data, my table gets enlarge vertically.
My problem is, if the data is more, it is not showing 10 records per page because in jasper we give static height of the page.
If i set more height of the page, then in that case if data is less, there is lots of invalid space on the report. Please help if someone faced this issue.
Issue Resolved.
I used frame (from Pallete ctrl+shift+8) within detail band and put all my cell data into frame. So, when page height is more, the blank space display instead of my last row height go increases.
Now, my cell could not stretched due to extra height of the page.

How to wrap a detail band in Jasper Reports

I have a detail band with potentially a lot of text fields in it. It can get too wide to fit on a page. The result is that it just runs off the edge of the page and you can't see it all. I'd like the detail band to wrap around to another line. Is there any way to do this?
My detail band is built dynamically in the code and the number of fields can vary. I tried manually placing the overflowing fields lower in the band by setting their y values, but then if the text in the fields overflows into two lines, my height calculations are off and the results get really messed up.
So is there any way to constrain the band to fit on the page?
Unfortunatelly, the strech types in jasper only works between bands, not within the band.
You can't (even manualy) create a jrxml which will cause a lower element in a band be correctly possitioned when an upper element overflows.
You will need to create more than one detail band. In iReport, you use 'Add another detail band' (on the detail band context-menu). Dynamically, it would look something like:
JRDesignSection detailSection = (JRDesignSection)design.getDetailSection();
JRDesignBand detail2 = new JRDesignBand();
detailSection.addBand(detail2);
Perhaps on your reportElement for each field in the band you need to set the attribute stretchType="RelativeToTallestObject".
<reportElement stretchType="RelativeToTallestObject" ...>
I'm pretty sure that's what works for me.

Programmatically move a FormulaFieldDefinition object

Given that FormulaFieldDefinition does not have a Top, Bottom, Left, or Right properties...is there any way to move/resize the formula at runtime?
You're looking at it the wrong way - a FormulaFieldDefinition is simply the definition of the formula itself, and not an object on the report. Therefore manipulating the size or position of it makes no sense.
What is actually shown on the report is an IFieldObject which displays the result for the given formula. This is how you can (if needed) show the same formula several times on a report.
You need to find the name of the IFieldObject that is displaying the formula, and manipulate the location of that instead. This can be done using ReportDefinition.ReportObjects("NameOfIFieldObject") and the Top, Left, Width and Height properties of it. Remember that the Top and Left values are relative to the section the object is in, not to the report.