Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to open blob/PDF in IE window

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 computer?" 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?

like image 817
SpaceCowboy74 Avatar asked Dec 23 '15 16:12

SpaceCowboy74


People also ask

How do I open a blob file in browser?

If you cannot open your BLOB file correctly, try to right-click or long-press the file. Then click "Open with" and choose an application. You can also display a BLOB file directly in the browser: Just drag the file onto this browser window and drop it.

What is blob in PDF?

The PDF file will be downloaded as BLOB (Binary Data) using XmlHttpRequest AJAX call and then will be sent for download in the Browser using JavaScript. Location of Files. The PDF file are stored in a folder named Files inside the project directory.


1 Answers

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 recommend you to use: pdf.js/.

like image 103
lesyk Avatar answered Oct 09 '22 03:10

lesyk