I've this Web API
post method to generate a PDF:
[HttpPost]
[Route("api/pdf")]
public HttpResponseMessage Post(CustomType type)
{
StreamContent pdfContent = PdfGenerator.GeneratePdf();
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = pdfContent;
response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = "PDFName.pdf"
return response;
}
In AngularJS I would like to get this PDF-file like this:
$http.post("api/pdf", object).then(function (results) {
var data = results.data;
//TODO: got PDF, how to handle?
}, function (results) {
console.log(results);
});
But how should I handle the PDF-data in AngularJS? On iPad I would like the PDF to gets opened, but if the file is downloaded or just opened on desktop doesn't matter.
EDIT1:
Using SaveAS JS library I'm able to make a working solution on desktop:
$http.post("api/pdf", object).then(function (results) {
var data = results.data;
var file = new Blob([data], { type: 'application/pdf' });
saveAs(file, "test.pdf");
}, function (results) {
console.log(results);
});
The file is being downloaded to my desktop directly, but this solution does, for some reason, not work in iOS. Nothing happens. See this JSFiddle.
Is there another way to display the PDF on my iPad without having to embed the file on my website?