I am trying to download a PDF file that is returned by a POST request:
Here is my Angular method:
sendPost: void {
const options = {headers: {'Content-Type': 'application/json'}};
this.http.post('http://localhost:8080/export', JSON.stringify(this.filter),
options )
.subscribe((next) => console.log(next));
}
And the Java backend that generates the PDF:
@CrossOrigin
@RequestMapping(value = "/export/", method = RequestMethod.POST)
public ResponseEntity<byte[]> getFilteredPDF(@RequestBody PdfExportFilter filter) throws IOException, DocumentException {
StructureExporter writer = new FilteredPdfExporter(filter);
Path filePath = Paths.get(writer.getBaseTempDir() + "/filteredExport.pdf");
writer.exportData();
return new ResponseEntity<byte[]>(readPdfBytes(filePath), getHttpHeaders("_filtered_export"), HttpStatus.OK);
}
How can I save the returned byte[]
into a PDF file so it gets downloaded to the client?