我必须使用五种不同的SQL查询来准备报告.每个查询都会给出一个报告表.
所以我写了5个jrxml文件,每个文件对应一个上面的查询,带有自己的标题,标题设置,页脚,页面编号等.
现在,我能够将上述每个jrxmls编译,打印和导出为5个不同的pdf.
但是,客户希望将所有报告整理成一个单独的pdf.那是在最后的pdf中,前四页将是报告一,接下来五页报告两页,然后报告三页,依此类推.
1)如何实现这一目标?
2)每个报告的页码为1/4,2/4,3/4等.其中第二部分即完整的页码用评估时间作为报告进行评估.因此,当我将单个pdf(如果可能)整理所有报告时,是否也可以将页面重新编号为最终pdf?
根据下面的答案,我在我的java类中做了以下工作,它的工作原理如下:
try
{
JasperReport jreport1 = JasperCompileManager.compileReport(input1);
JasperPrint jprint1 = JasperFillManager.fillReport(jreport1, new HashMap(), new JREmptyDataSource());
//JasperExportManager.exportReportToPdfFile(jprint, "/home/ashutosh/Desktop/desktop/nikunj/JasperTestApp/output/mytest.pdf");
JasperReport jreport2 = JasperCompileManager.compileReport(input2);
JasperPrint jprint2 = JasperFillManager.fillReport(jreport2, new HashMap(), new JREmptyDataSource());
JasperReport jreport3 = JasperCompileManager.compileReport(input3);
JasperPrint jprint3 = JasperFillManager.fillReport(jreport3, new HashMap(), new JREmptyDataSource());
List<JasperPrint> jprintlist = new ArrayList<JasperPrint>();
jprintlist.add(jprint1);
jprintlist.add(jprint2);
jprintlist.add(jprint3);
JRExporter exporter = new JRPdfExporter();
exporter.setParameter(JRPdfExporterParameter.JASPER_PRINT_LIST, jprintlist);
OutputStream output = new FileOutputStream(new File("/home/ashutosh/Desktop/desktop/nikunj/JasperTestApp/output/mytestbatch.pdf"));
exporter.setParameter(JRPdfExporterParameter.OUTPUT_STREAM, output);
exporter.exportReport();
}catch(Exception e)
{
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
上图:input1,input2,input3是输入jrxmls的字符串路径
我的JRXML文件只打印三条消息:Hello World 1,Hello …