My Angular 1.5 app connects to a backend server running Java, Tomcat, and Spring via REST.
One of the REST services generates PDF files and sends them to clients. While this works well on desktop browsers like Firefox and Chrome, I'm facing an issue where the PDF content is not visible on iOS devices such as iPads, regardless of the browser being used (Chrome or Safari).
Below is the Angular code snippet:
$http.get("/displayPdf", {responseType: 'arraybuffer', params: {id: 1}}).
success(function(data) {
var blob = new Blob([data], {type 'application/pdf'});
var objectUrl = window.URL.createObjectURL(blob);
window.open(objectUrl);
}
);
The corresponding Spring/Jax-RS code is as follows:
@GET
@Path("displayPdf")
@Produces("application/pdf")
Response displayPdf(@QueryParam("id") Long id) {
byte[] bytes = service.generatePdf();
return javax.ws.rs.core.Response.ok().
entity(bytes).
header("Content-Type", "pdf").
header("Content-Disposition", "attachment; filename='test.pdf'").
build();
}
I have looked into solutions such as the one mentioned here (AngularJS: Display blob (.pdf) in an angular app), but have not found a suitable fix.
If anyone has any insights on how I can resolve this issue and successfully display generated PDFs to iPad/iPhone users, I would greatly appreciate it.
Thank you!