, , , , , . , , , JasperReports.
1.-
, 2 , . PAGE_COUNT_OFFSET Integer. , , :
<pageFooter>
<band height="54" splitType="Stretch">
<textField>
<reportElement x="146" y="2" width="100" height="30" uuid="1314c392-e24a-47bd-a0aa-6b19803be36a"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA["- Page " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement x="246" y="2" width="100" height="30" uuid="230a6e2d-3e6d-4d52-9228-aab519122537"/>
<textElement textAlignment="Left"/>
<textFieldExpression><![CDATA[" of " + ($V{PAGE_NUMBER} + $P{PAGE_COUNT_OFFSET}) + " -"]]></textFieldExpression>
</textField>
</band>
</pageFooter>
<pageFooter>
<band height="50">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<textField>
<reportElement x="146" y="2" width="100" height="30" uuid="b6a836b2-41f5-4a61-af64-50720544cef2"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA["- Page " + ($V{PAGE_NUMBER} + $P{PAGE_COUNT_OFFSET})]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement x="246" y="2" width="100" height="30" uuid="be5469d3-10ed-4deb-964d-c1f9c9b7337a"/>
<textElement textAlignment="Left"/>
<textFieldExpression><![CDATA[" of " + ($V{PAGE_NUMBER} + $P{PAGE_COUNT_OFFSET}) + " -"]]></textFieldExpression>
</textField>
</band>
</pageFooter>
: , .
2.-
, , .jasper . Java-. main, - .
. , .jasper JAR .
public static void main(String[] args) {
try {
Map<String, Object> subreportParams = new HashMap<>();
subreportParams.put(PARAM_PAGE_COUNT_OFFSET, 10);
Map<String, Object> mainParams = new HashMap<>(subreportParams);
mainParams.put(...);
ClassLoader classLoader = getClass().getClassLoader();
JasperPrint main = JasperFillManager.fillReport(classLoader.getResourceAsStream(MAIN_REPORT_FILE), mainParams, JdbcManager.getConnection());
JasperPrint subreport = JasperFillManager.fillReport(classLoader.getResourceAsStream(SUBREPORT_FILE), subreportParams, JdbcManager.getConnection());
int mainPageCount = main.getPages().size();
int subreportPageCount = subreport.getPages().size();
mainParams.put(PARAM_PAGE_COUNT_OFFSET, subreportPageCount);
subreportParams.put(PARAM_PAGE_COUNT_OFFSET, mainPageCount);
main = JasperFillManager.fillReport(classLoader.getResourceAsStream(MAIN_REPORT_FILE), mainParams, JdbcManager.getConnection());
subreport = JasperFillManager.fillReport(classLoader.getResourceAsStream(SUBREPORT_FILE), subreportParams, JdbcManager.getConnection());
List<JasperPrint> finalReport = new ArrayList<>();
finalReport.add(main);
finalReport.add(subreport);
JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(SimpleExporterInput.getInstance(finalReport));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(
new FileOutputStream("path/to/report.pdf")));
exporter.exportReport();
} catch (JRException ex) {
LOGGER.log(Level.SEVERE, "Error generating report", ex);
} catch (FileNotFoundException ex) {
LOGGER.log(Level.SEVERE, "Error saving file", ex);
}
}
, PDF . , . .