admin管理员组

文章数量:1323729

I have the code below in my typescript to call a web api method and retrieve a binary byte array (blob) that is a PDF. My user requirement is to open PDF in a new window.

$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
            });
        });
    }

This code works fine in Chrome. The document opens as expected. IE however asks "Do you want to allow this website to open an app on your puter?" and when allowed, tell me "No apps are installed to open this kind of link (blob)".

Any ideas on how to open this in a new tab or save the blob as a file as a last resort?

I have the code below in my typescript to call a web api method and retrieve a binary byte array (blob) that is a PDF. My user requirement is to open PDF in a new window.

$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
            });
        });
    }

This code works fine in Chrome. The document opens as expected. IE however asks "Do you want to allow this website to open an app on your puter?" and when allowed, tell me "No apps are installed to open this kind of link (blob)".

Any ideas on how to open this in a new tab or save the blob as a file as a last resort?

Share Improve this question edited Nov 16, 2017 at 9:12 lesyk 4,1293 gold badges28 silver badges39 bronze badges asked Dec 23, 2015 at 16:39 SpaceCowboy74SpaceCowboy74 1,4211 gold badge25 silver badges47 bronze badges 1
  • 3 Wild guess: There are similarly-looking questions that may be of some help: stackoverflow./questions/28196065/…, stackoverflow./questions/24007073/… Specifically this IE-specific line may be of interest: window.navigator.msSaveOrOpenBlob(blobObject, fileName); – MartyIX Commented Jan 5, 2016 at 14:53
Add a ment  | 

1 Answer 1

Reset to default 3

The reason why it works in Chrome and other normal browsers: they have pdf previewer installed inside of them.

The lease why it does not work in IE: since in architecture if IE there should be some PDF reading program installed on operating system; for instance, if you have Adobe Acrobat installed, you will open it without problems.

I can remend you to use: pdf.js/.

本文标签: javascriptNeed to open blobPDF in IE windowStack Overflow