如何将两个jrxml jasper报告合并为1 pdf同一页面 [英] How to merge two jrxml jasper report into 1 pdf same page
本文介绍了如何将两个jrxml jasper报告合并为1 pdf同一页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试从这个网站回答将两个jrxml jasper合并为1个pdf文件。创建的文件包含两个页面...
I tried answer from this site to merge two jrxml jasper into 1 pdf file. Created file contain two page...
如何将两个jrxml合并到一个页面中?
How to merge two jrxml into one page?
JasperPrint jasperPrint1 = JasperFillManager.fillReport(getClass().getResourceAsStream("/coba.jasper"), param, new JREmptyDataSource());
JasperPrint jasperPrint2 = JasperFillManager.fillReport(getClass().getResourceAsStream("/coba2.jasper"), param2, new JREmptyDataSource());
List pages = jasperPrint2.getPages();
for (int i = 0; i < pages.size(); i++) {
JRPrintPage object = (JRPrintPage)pages.get(i);
jasperPrint1.addPage(object);
}
JRExporter exporter = new JRPdfExporter();
exporter.setParameter(JRPdfExporterParameter.JASPER_PRINT_LIST, jasper);
OutputStream output = new FileOutputStream(new File("d:\\demo.pdf"));
exporter.setParameter(JRPdfExporterParameter.OUTPUT_STREAM, output);
exporter.exportReport();
推荐答案
这是因为你要添加页面 addPage
,您需要将页面上的元素添加到另一个页面。
This is since you are adding a page addPage
, you need to add the elements on a page to another page.
JRPrintPage page1 = jasperPrint1.getPages().get(0);
List<JRPrintPage> pages2 = jasperPrint2.getPages();
for (JRPrintPage page : pages2) {
List<JRPrintElement> elements = page.getElements();
for (JRPrintElement element : elements) {
page1.addElement(element);
}
}
此代码将添加<$ c $的所有元素c> jasperPrint2 (在其所有页面中)第1页 jasperPrint1
This code will add all elements of jasperPrint2
(in all its pages) in page 1 on jasperPrint1
注意:错误处理( Nullpointer
, ArrayIndexOutOfBounds
)超出了示例的范围。
NOTE: Error handling (Nullpointer
, ArrayIndexOutOfBounds
) is beyond the scope of the example.
这篇关于如何将两个jrxml jasper报告合并为1 pdf同一页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文