I'm creating an application where I need to return a PDF via an API call developed in Spring Boot through AngularJS, my code looks like the one below:
API Return:
ResponseEntity.ok()
.headers(result.getHttpHeaders())
.body(new InputStreamResource(result.getInputStream()));
Where the header is application / pdf
Angular CodeJS:
$http.get("path/pdf",
{ params: params },
{ responseType: "arraybuffer" }
)
.then(function(response){
console.log(response.data);
var blob = new Blob([response.data], {type: 'application/pdf'});
FileSaver.saveAs(blob, 'arquivo.pdf');
});
As a result, the PDF generated by FileSaver is left blank, even the response.data , with the data being.
When calling the API url directly from the browser, the PDF is returned normally.