Hi,
I'm currently trying to add a text element programatically in a JRPrintPage object.
I've a working full report which is build by concatenating multiple reports, I've had to do this in order to mix portrait and landscape report.
My problem is that I have to insert page number inside the pageFooter of those page after filling these reports. I have the total number of page and also the number of the current page.
JasperReports version : 6.2.0
I've tried the following without any success :
private void drawPageNumbers(List<JasperPrint> listJasperPrint, int totalPages) throws JRException { int pageCount = 0; int posY = 0; int posX = 0; for (JasperPrint jasperPrint : listJasperPrint) { if (jasperPrint.getOrientationValue() == OrientationEnum.PORTRAIT) { posY = 9; posX = 273; } //ToDo /*if (jasperPrint.getOrientationValue() == OrientationEnum.LANDSCAPE) { posY = 558; posX = 717; }*/ for (JRPrintPage jrPrintPage : jasperPrint.getPages()) { pageCount++; //get Footer JRPrintElement jrPrintElement = jrPrintPage.getElements().get(jrPrintPage.getElements().size()-1); //JRPrintText textPageNumber = new JRTemplatePrintText(new JRTemplateText(originFooter, jasperPrint.getDefaultStyleProvider())); JRBasePrintText textPageNumber = new JRBasePrintText(jasperPrint.getDefaultStyleProvider()); textPageNumber.setX(posX); textPageNumber.setY(posY); textPageNumber.setWidth(54); textPageNumber.setHeight(12); textPageNumber.setText(pageCount + " / " + totalPages); jrPrintElement.addElement(textPageNumber); } }
The jrxml structure of the PageFooter is the following:
<pageFooter> <band> <frame> <!-- various text element --> </frame> </band></pageFooter>
Hope someone can help me, if you need more informations, don't hesitate to ask them !
Thanks in advance,
Jim