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.
How can i produce ONE pdf file from the two jasperprints keeping their original orientation?
I have the following code :
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With