如何组合多个JasperPrint对象以使一个报表具有混合页面方向 [英] How to combine several JasperPrint objects to have one report with mixed page orientation
问题描述
jasperPrint
对象具有纵向方向,但 jasperPrint2
对象具有横向方向。我想结合两个jasperprints来制作一个pdf文件,但保持原来的方向。当我将jasperPrint2的页面添加到jasperPrint时,最终的jasperPrint具有纵向方向......我测试了 jasperPrint.setOrientation(JasperReport.ORIENTATION_LANDSCAPE)
但没有任何改变。
The jasperPrint
object has portrait orientation, but jasperPrint2
object has landscape orientation. I want to combine the two jasperprints to produce ONE pdf file but keeping their original orientation. When i add the jasperPrint2's pages to the jasperPrint then the final jasperPrint has portrait orientation... I tested the jasperPrint.setOrientation(JasperReport.ORIENTATION_LANDSCAPE)
but nothing changed.
我如何从保持原始方向的两个jasperprints中生成一个pdf文件?
How can i produce ONE pdf file from the two jasperprints keeping their original orientation?
我有以下代码:
JasperReport report = (JasperReport) JRLoader.loadObject(reportFile2.getPath());
jasperPrint = JasperFillManager.fillReport(report, parameters, conn);
JasperReport report2 = (JasperReport) JRLoader.loadObject(reportFile.getPath());
jasperPrint2 = JasperFillManager.fillReport(report2, parameters, conn);
List pages = jasperPrint2.getPages();
for (int j = 0; j < pages.size(); j++) {
JRPrintPage object = (JRPrintPage) pages.get(j);
jasperPrint.addPage(object);
}
推荐答案
你可以做到这一点批量导出。
You can accomplish this by doing a batch export.
//put all the jasperPrints you want to be combined into a pdf in this list
List<JasperPrint> jasperPrintList = new ArrayList<JasperPrint>();
JasperReport report = (JasperReport) JRLoader.loadObject(reportFile2.getPath());
jasperPrintList.add(JasperFillManager.fillReport(report, parameters, conn));
JasperReport report2 = (JasperReport) JRLoader.loadObject(reportFile.getPath());
jasperPrintList.add(JasperFillManager.fillReport(report2, parameters, conn));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JRPdfExporter exporter = new JRPdfExporter();
//this sets the list of jasperPrint objects to be exported and merged
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList);
//the bookmarks is a neat extra that creates a bookmark for each jasper print
exporter.setParameter(JRPdfExporterParameter.IS_CREATING_BATCH_MODE_BOOKMARKS, Boolean.TRUE);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
exporter.exportReport();
return baos.toByteArray();
这篇关于如何组合多个JasperPrint对象以使一个报表具有混合页面方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!