Hello,
I have a requirement to open the pdf in window where the pdf is returned from the Web API and show in the AngularJs application.
Thanks for your help
What I have tried:
When I invoke the Web API method directly the PDF is appropriately getting exported, but when I'm trying to handle the export done in AngularJs using the below mentioned code it shows invalid document or corrupted document.
function openPDF(resData, fileName) {
var ieEDGE = navigator.userAgent.match(/Edge/g);
var ie = navigator.userAgent.match(/.NET/g);
var oldIE = navigator.userAgent.match(/MSIE/g);
var blob = new window.Blob([resData], { type: 'application/pdf' });
if (ie || oldIE || ieEDGE) {
window.navigator.msSaveBlob(blob, fileName);
}
else {
var reader = new window.FileReader();
reader.onloadend = function () {
window.location.href = reader.result;
window.target = "_blank";
};
reader.readAsDataURL(blob);
}
}
Web API response
HttpResponseMessage result = null;
result = Request.CreateResponse(HttpStatusCode.OK);
result.Content = new ByteArrayContent(bytes);
result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
result.Content.Headers.ContentDisposition.FileName = "Test.pdf";
return result;