I am using JasperExportManager to export pdf as byte[] and then convert it to string to be able to add it to the response JSON object.
In the front end in angular I can't convert it back to a byte array to save it again I may be able to save it with lifesaver lib but it won't open the pdf is corrupted
here is my service code:
InputStream jrxmlFile =
myclass.class.getResourceAsStream("/myjrxml.jrxml");
// Map params = new HashMap();
HashMap reportParameters = new HashMap();
reportParameters.put("Parameter1", goodsIssueCode);
JasperReport jasperReport = JasperCompileManager.compileReport(jrxmlFile);
JasperPrint report =
JasperFillManager.fillReport(jasperReport, reportParameters, dataSource.getConnection());
report.addStyle(prepareNormalStyle());
byte[] pdf = JasperExportManager.exportReportToPdf(report);
// Export pdf file
return getSuccessResponse(pdf.toString());
And my front end function:
mergeMap(response => {
let b: any = new Blob([response['code']], { type: 'application/pdf' });
FileSaver.saveAs(b, 'mypdf.pdf');
return [];
})