I have a report which contains several subreports, so several jrxml files. I assume that page numbering is controlled by the composite element "page number"? I right click on "page number" and then click on layout and settings. But I don't find any way of changing the font.
1 Answer:
The composite elements are simply text fields with the appropriate expression. Once you put them on the canvas, you can change the attributes to meet your needs.
Since you mentioned that you have many subreports will say that the $V{PAGE_NUMBER} that is used by the page number and total pages does not take the space of subreports into consideration. You will need to use $V{MASTER_CURRENT_PAGE} and $V{MASTER_TOTAL_PAGES} then set the evaluation time to "Master".
Page N of M
Expression: "Page " + TEXT($V{MASTER_CURRENT_PAGE}, "#,###") + " of " + TEXT($V{MASTER_TOTAL_PAGES}, "####")
Evaluation Time: Master
Â
Page N
Expression: "Page " + TEXT($V{MASTER_CURRENT_PAGE}, "#,###")
Evaluation Time: Master
Â
2/22/2023
Thanks for the follow-up. I see you are using code, not Jasper Studio, to create the jrxml file. The solution is the same. I will follow up by providing the jrxml of my page header and displaying the expression editor.
Page Header
<pageHeader> <band height="56" splitType="Stretch"> <staticText> <reportElement x="265" y="1" width="222" height="34" uuid="27d6c2b1-30b7-4704-a78a-45b5eae41c9e"/> <textElement textAlignment="Center"> <font fontName="Arial" size="18" isBold="true"/> </textElement> <text><![CDATA[Example of Summaries]]></text> </staticText> <textField evaluationTime="Master"> <reportElement x="519" y="12" width="233" height="13" uuid="b9164ec1-ad06-4dae-b0ce-3e8151779813"> <property name="com.jaspersoft.studio.unit.y" value="px"/> </reportElement> <textElement textAlignment="Right"> <font fontName="Arial" size="8"/> </textElement> <textFieldExpression><![CDATA["Page " + TEXT($V{MASTER_CURRENT_PAGE}, "#,###") + " of " + TEXT($V{MASTER_TOTAL_PAGES}, "####")]]></textFieldExpression> </textField> <textField evaluationTime="Auto" pattern="EEEE MM/dd/yyyy h:mm a"> <reportElement x="522" y="1" width="230" height="12" uuid="f568815e-b548-4679-baa5-91cc04c62f18"/> <textElement textAlignment="Right"> <font fontName="Arial" size="8"/> </textElement> <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression> </textField> </band> </pageHeader>
Expression Editor
There are 7 default variables that every report has access to (PAGE_NUMBER, MASTER_CURRENT_PAGE, MASTER_TOTAL_PAGE, COLUMN_NUMBER, REPORT_COUNT, PAGE_COUNT, and COLUMN_COUNT). You can see those in the expression editor below.
I don't find any master page, so it is difficult to apply your solution. I took over this project from a consultant, who build it. The subreports are put together by Java code. Do I have to have a master page to set the page number ? I don't find any component related to page number in the pages. How come the page numbers are shown then? Is it default numbering? This is my code:
ReportTemplateItem reportTemplateItem = (ReportTemplateItem) item;
addPageHeader(reportBuilder, report, messages, reportTemplateItem);
addPageFooter(reportBuilder, report, messages, reportTemplateItem);
reportHeaderNationalApplication.createSubreport(reportBuilder, report, item, messages);
writtenReplyMustBeReceived.createSubreport(reportBuilder, report, item, messages);
horizontalLine.createSubreport(reportBuilder, report, item, messages);
reportHeaderTemplateText.createSubreport(reportBuilder, report, item, messages);
nationalOfficerSignature.createSubreport(reportBuilder, report, item, messages);
Do you mean that I have to add a <pageHeader> with <textField evaluationTime="Master">? Then I should set the font of the page number in that textfield? There is no <pageHeader> in my files. The font of the page number is set nowhere, but it is SansSerif 10. Is this the default page number font, which comes by default from Jasper Studio? Is this where you set the font of the page number?Â
<textField evaluationTime="Master">
<reportElement x="519" y="12" width="233" height="13" uuid="b9164ec1-ad06-4dae-b0ce-3e8151779813">
<property name="com.jaspersoft.studio.unit.y" value="px"/>
</reportElement>
<textElement textAlignment="Right">
<font fontName="Arial" size="8"/>
</textElement>