I have a link on my page on click of which I am trying to generate a PDF document and then show the \"Open - Save\" prompt on the browser.
My HTML (reactjs component
In our app(angular) we had to create an object url for that with a code like:
WebApi:
result = Request.CreateResponse(HttpStatusCode.OK);
result.Content = new ByteArrayContent(data);
result.Content.Headers.Add("Content-Type", "application/pdf");
result.Content.Headers.ContentDisposition =
new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
{
FileName = "FileNameHere"
};
return result;
javascript:
// HttpCall in here
// On SuccessResponse
var file = new Blob([data], {
type: 'application/pdf'
});
var fileURL = URL.createObjectURL(file);
// create an anchor and click on it.
var ancorTag = document.createElement('a');
ancorTag.href = fileURL;ancorTag.target = '_blank';
ancorTag.download = 'CouponOrder.pdf';
document.body.appendChild(ancorTag);
ancorTag.click();
document.body.removeChild(ancorTag);