如何在报告中插入两个页面 [英] How to insert two pages in report
问题描述
我遇到一个问题,我有两个 jrmxl
文件。我想加入一个 pdf
文件,但每个都在一个页面中。
I´m facing one problem, I have two jrmxl
files. I want to join then in one pdf
file, but each in one page.
我在下面看到了一些提示,但我不知道它们是否是最好的,因为我的第一个文件有3个乐队: title
,详细信息
和摘要
。第二个有详细信息
和摘要
。
I saw some tips below but I don´t know if they are the best, because my first file have 3 bands: title
, detail
and summary
. The second have detail
and summary
.
所以我如果可能的话,我想保留这种格式,因为在摘要中有页面计数器。
So I want to keep this format if is possible, because in the summary have the page counter.
我试过这个,但我的第二页是空白的,有5厘米的高度。
I´ve tried this but my second page is blank and have 5 cm of heigth.
列表页数=新的ArrayList<>();
List pages = new ArrayList<>();
for (String caminhoRelatorio : caminhoRelatorios) {
reportPath = JasperCompileManager.compileReport(caminhoRelatorio);
reportPage = JasperFillManager.fillReport(reportPath, parameters, ds);
pages.add(reportPage);
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JRPdfExporter jrPdfExporter = new JRPdfExporter();
jrPdfExporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, pages);
jrPdfExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
jrPdfExporter.setParameter(JRPdfExporterParameter.IS_CREATING_BATCH_MODE_BOOKMARKS, Boolean.TRUE);
jrPdfExporter.exportReport();
那么我需要做什么?
推荐答案
要在一个报告/ PDF中添加多个JRXML,您可以按照下面提到的方式:
To add multiple JRXMLs in one report/PDF, you can follow the below mentioned way:
考虑以下方法生成包含2个JRXML的PDF报告,其中添加了jrxmlFileNames列表
Consider the method below to generate a PDF report with 2 JRXMLs which have added in the "jrxmlFileNames" list
public static void reportGenerator(String reportType, List<String> jrxmlFileNames,
Datasource dataSource , String SwapFile)
{
JRConcurrentSwapFile swapFile = new JRConcurrentSwapFile(SwapFile, 102400 , 10);
JRAbstractLRUVirtualizer virtualizer = new JRSwapFileVirtualizer(1000, swapFile, true);
Map<String, JRAbstractLRUVirtualizer> parameters = new HashMap<String, JRAbstractLRUVirtualizer>();
parameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);
try
{
if (reportType.equalsIgnoreCase("PDF"))
{
try
{
JasperReport jreport1 = JasperCompileManager.compileReport(ReportGenerator.class.getResourceAsStream(jrxmlFileNames.get(0)));
JasperPrint jprint1 = JasperFillManager.fillReport(jreport1, parameters, new JRBeanCollectionDataSource(dataSource.getDataSourceFor1()));
JasperReport jreport2 = JasperCompileManager.compileReport(ReportGenerator.class.getResourceAsStream(jrxmlFileNames.get(1)));
JasperPrint jprint2 = JasperFillManager.fillReport(jreport2, parameters, new JRBeanCollectionDataSource(dataSource.getDataSourceFor2()));
List<JasperPrint> jprintlist = new ArrayList<JasperPrint>();
jprintlist.add(jprint1);
jprintlist.add(jprint2);
String fileName="TESTReport.pdf";
JRExporter exporter = new JRPdfExporter();
exporter.setParameter(JRPdfExporterParameter.JASPER_PRINT_LIST, jprintlist);
exporter.setParameter(JRPdfExporterParameter.OUTPUT_FILE_NAME, fileName);
exporter.exportReport();
}
catch(Exception e)
{
e.printStackTrace();
}
}
swapFile.dispose();
}
catch(Exception e)
{
e.printStackTrace();
}
}
在上面的代码中,以下部分将帮助您添加多个JRXML
In the above code the following part will help you adding the multiple JRXMLs
List<JasperPrint> jprintlist = new ArrayList<JasperPrint>();
jprintlist.add(jprint1);
jprintlist.add(jprint2);
JRExporter exporter = new JRPdfExporter();
exporter.setParameter(JRPdfExporterParameter.JASPER_PRINT_LIST, jprintlist);
希望有所帮助!
这篇关于如何在报告中插入两个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!