Closed heyizhiyuan closed 1 month ago
When you say "multiple reports", do you mean they are run independent of one another and they need to be put together later on by some program?
If the reports are supposed to be run together in a single shot, they ca be bundled as parts in a book report.
See the book sample for details. https://jasperreports.sourceforge.net/sample.reference/book/README.html#parts
I hope this helps. Teodor
Yes. Multiple reports are independent and need to be combined by some program.Something like this:
My current approach, "setIgnorePagination," doesn't seem to be working:
JasperReportBuilder mainReport = DynamicReports.report();
mainReport.setShowColumnTitle(false);
mainReport.setTitleOnANewPage(false);
mainReport.setSummaryOnANewPage(false);
mainReport.setSummaryWithPageHeaderAndFooter(false);
mainReport.setFloatColumnFooter(false);
mainReport.setDataSource(new JREmptyDataSource());
mainReport.setPageColumnSpace(0);
mainReport.setPageHeaderSplitType(SplitType.STRETCH);
mainReport.setDetailSplitType(SplitType.STRETCH);
mainReport
.setPageMargin(
DynamicReports.margin()
.setBottom(0)
.setLeft(0)
.setRight(0)
.setTop(0)
);
SubreportBuilder[] subreportBuilders = exportParameters.stream()
.map(exportParameter -> {
JasperReportBuilder jasperReportBuilder = new JasperReportBuilder();
try {
jasperReportBuilder.setTemplateDesign(exportParameter.getJasperDesign())
.setParameters(exportParameter.getParameters())
.setConnection(Optional.ofNullable(exportParameter.getConnection()).orElse(connection))
.setIgnorePagination(exportParameter.getJasperDesign().isIgnorePagination());
} catch (DRException e) {
throw new ReportException(e);
}
return Components.subreport(jasperReportBuilder)
.setParameters(exportParameter.getParameters());
}).toArray(SubreportBuilder[]::new);
mainReport.addDetail(subreportBuilders);
JasperReport jasperReport = mainReport.toJasperReport();
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, mainReport.getJasperParameters(), mainReport.getDataSource());
Sorry, but you posted here some API we are not familiar with. Maybe you should check with the authors of that API.
To answer your initial question, I would ask you back another one: If reports are run independent of one another, then how is one report supposed to know what page it starts on or what is its position in the overall list of reports that will be stitched together?
We are talking here about custom Java code that manipulates reports after they are run and this is not something we can help with. This is code you probably wrote in your own java application that uses our library. The JasperReports engine cannot take care of page numbering logic that sits outside its business logic. There is no way for JasperReports to know what you plan to do with these reports after they are run.
Maybe you need to reconsider your approach and run reports together as parts in a book, as I suggested above. In that case, JasperReports would know the order in which they are run and would be able to keep track of current page number across multiple reports ran as parts of the overall "book".
Otherwise, you would probably need to enhance your code and post-process each individual generated report and "manually" modify page numbers, but this would be overkill and I'm not recommending it.
Maybe in the program you have, you can keep track of reports already generated and pass the current page count as parameter to the next reports, which would add it to the PAGE_NUMBER variable when displaying it in the report page footer (or elsewhere in the report).
Thanks, Teodor
If you still have this issue and can provide more information about your use case, feel free to reopen it. Until then, I'm closing it.
Thank you, Teodor
How to achieve multiple reports combined printing, and to have continuous page numbers.There may even be some reports that do not participate in counting.