I've got an existing dynamic jasper report that I need to modify so that the page orientation and size can be set dynamically. I've been able to achieve this using the dynamicReportBuilder.setPageSizeAndOrientation(...)
. The trouble is that when I change page sizes the title is no longer in the middle of the page...
I'm defining the title like:
<title>
<band height="20" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="760" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="ConjectSans" size="14" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[$P{title}]]>
</textFieldExpression>
</textField>
</band>
</title>
Is there any way I can change the above so that the title text will float to the middle of the page regardless of what size I set the page?
From what I've googled I I can't set the width attribute dynamically in the jrxml
, instead I need to do something like:
JRElement element = jasperReport.getTitle().getElementByKey("graphWidthKey");
element.setWidth(100);
But how do I get access to the JasperReport
object from the dynamic Jasper's DynamicReportBuilder
?
You cannot do that. the JasperReport object is a read-only object. It is the result of compiling the JasperDesign object.
Being able to set up the page size programatically makes it dynamic! if you need to change it again, then generate the report again.