我的 typescript 中有以下代码,用于调用 Web API 方法并检索作为 PDF 的二进制字节数组 (blob)。我的用户要求是在新窗口中打开 PDF。
$scope.selectRow = (itemImageNumber: string, printProcessId: string, printXmlId: string) => {
itemService.GetOutgoingDocument($scope.item.ItemId, itemImageNumber, printProcessId, printXmlId).success((response) => {
var file = new Blob([response], { type: 'application/pdf' });
var fileUrl = URL.createObjectURL(file);
//$scope.outDocContent = $sce.trustAsResourceUrl(fileUrl);
var win = window.open($sce.trustAsResourceUrl(fileUrl));
win.focus();
}).error(() => {
var message =
"The document you selected can’t be displayed at this time. Please call Customer Service at xxx-xxx-xxxx for assistance.";
$rootScope.$broadcast("app-message", {
type : "danger",
message : message
});
});
}
此代码在 Chrome 中运行良好。文档按预期打开。然而,IE 会询问“您要允许此网站在您的计算机上打开应用程序吗?”当允许时,告诉我“没有安装任何应用程序来打开这种链接(blob)”。
作为最后的手段,关于如何在新选项卡中打开它或将 blob 另存为文件有什么想法吗?
最佳答案
它在 Chrome 和其他普通浏览器中工作的原因:它们内部安装了 pdf 预览器。
为什么它在 IE 中不起作用:因为在体系结构中,如果 IE 应该在操作系统上安装一些 PDF 阅读程序;例如,如果您安装了 Adobe Acrobat,则可以毫无问题地打开它。
我可以推荐您使用:pdf.js/ .
关于javascript - 需要在IE窗口打开blob/PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34440114/