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

0

Hi,

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<>();
printList.add(mainReport);
printList.add(tableReport);
 
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
exporter.setConfiguration(configuration);
exporter.exportReport();

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: 2 months 1 week ago

1 Answer:

0

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

http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/exp...

hozawa's picture
45109
Joined: Apr 24 2010 - 4:31pm
Last seen: 1 month 1 week ago
Feedback