How to export print list of two documents as byte array?


I have a code like this:

mainReport = JasperFillManager.fillReport(report, invoiceMap, new JREmptyDataSource());
tableReport = JasperFillManager.fillReport(table, taskListMap, new JREmptyDataSource());
List<JasperPrint> printList = new ArrayList<>();
JRPdfExporter exporter = new JRPdfExporter();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
exporter.setExporterInput(SimpleExporterInput.getInstance(printList)); //Set as export input my list with JasperPrint s
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(System.getProperty("user.home") + "/output.pdf")); //or any other out streaam
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
configuration.setCreatingBatchModeBookmarks(true); //add this so your bookmarks work, you may set other parameters

But it is exporting the report to a file. I need to change this code so it is returning a byte[] so I can make an rest service endpoint to download the file... But I don't seem to find a method to do this...

zbigniew.nitecki's picture
Joined: Mar 21 2019 - 2:21am
Last seen: 3 years 10 months ago

is there any way to sort the printList?

Nilam1.K - 7 months 1 week ago

1 Answer:

Have you tried exporting to ByteArrayOutputStream using export.exportReportToStream() and then converting it to .toByteArray()?

hozawa's picture
Joined: Apr 24 2010 - 4:31pm
Last seen: 3 years 9 months ago