Reputation: 40850
I have the following report:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd"
name="demo" pageWidth="595" pageHeight="842" columnWidth="515" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<style name="highlight box" mode="Opaque" backcolor="#D9D9D9">
<box padding="2" />
</style>
<lastPageFooter>
<band height="30">
<textField isStretchWithOverflow="true">
<reportElement style="highlight box" x="0" y="0" width="320" height="1" />
<textFieldExpression><![CDATA["This is a short footer content\nIt contains multiple lines"]]></textFieldExpression>
</textField>
</band>
</lastPageFooter>
</jasperReport>
As you can see the report contains nothing but the lastPageFooter
which contains a text field width dynamic (isStretchWithOverflow="true"
) height.
However it appears that Jasper will place the lastPageFooter
always so that is begins 30pixels (as defined in <band height="30">
) before the end of the page. If 30 pixels is not enough due to the height of the textField, the band is stretched, but it is stretched downward, past the end of the page rather than upward. This causes some of the content of the footer not to be rendered. Actually the report above renders like this:
As you can see the second line in the textField is missing. I can of course increase the band height to let's say... 100 pixel:
In this case the second line of the text field is rendered, but 100px was clearly too much and the footer is not at the end of the page anymore.
In this case the text field contains static text so I could try values for height, so that this fits, but in the real world the content of the text field comes from a variable. How can I get the footer to show at the bottom of the page with a dynamic height?
Upvotes: 1
Views: 1285
Reputation: 328770
You will have to use a trick because footer bands don't stretch (the engine needs to know in advance whether they will fit on the page). See "Understanding Bands" in the documentation.
Workarounds:
background
band. Use printWhenExpression
to show only one of them. Works best when there is no word wrapping because then, you can calculate the height from the number of lines and the font size.com.itextpdf.text.pdf.PdfStamper
to write the footers after JasperReports gave you a PDF. Gives you full control but is slow (especially for large PDFs) and memory intensive.Upvotes: 0
Reputation: 6663
Try changing the Split Type on the Page Footer. You could try "Stretch" or "Prevent".
Upvotes: -1