我有一个角度应用程序,可以在blob中加载流并在浏览器中显示。我可以使用以下代码在谷歌浏览器和Firefox中打开,但不能在Internet Explorer中打开。我使用if条件如下,Internet Explorer没有提示打开或保存。有没有办法,我可以强制提示直接打开。如果有任何其他代码支持在浏览器中显示pdf,也不胜感激。
我的javascript代码。
$http.post(apiURL + "/save", data, config)
.then(function (SuccessData) {
if (validateResponse(SuccessData.data, "Submit")) {
return;
}
$scope.Result = SuccessData.data;
data.CommissionId = SuccessData.data.CommissionId;
$http.post(apiURL + "/DownloadPdf", data,
{ responseType: 'arraybuffer' }, config)
.then(function (result) {
var file = new Blob([result.data], { type: 'application/pdf' });
var fileName = "CommissionStatement.pdf";
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(file, fileName);
}
else {
var objectUrl = URL.createObjectURL(file, fileName);
window.open(objectUrl);
}
});
},
function (error) {
$scope.Error = error.data;
});
这是我从api背后的代码 reportDocument.SetParameterValue(0,commissionId); var exportOptions = reportDocument.ExportOptions; exportOptions.ExportDestinationType = ExportDestinationType.NoDestination; exportOptions.ExportFormatType = ExportFormatType.PortableDocFormat; var req = new ExportRequestContext {ExportInfo = exportOptions}; var stream = reportDocument.FormatEngine.ExportToStream(req);
tempResponse = Request.CreateResponse(HttpStatusCode.OK);
tempResponse.Content = new StreamContent(stream);
tempResponse.Content.Headers.Add(@"Content-type", "application/pdf");
tempResponse.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue
("application/pdf");
tempResponse.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("inline");
感谢。