0

I currently take a base 64 encoded string that represents a PDF file and convert it to a blob in AngularJS using the following code (simplified):

var base64PdfToBlob = function(b64Data: string, contentType: string) {
                    var sliceSize = 512;
                    var byteCharacters = atob(b64Data);
                    var byteArrays = [];

                    for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
                        var slice = byteCharacters.slice(offset, offset + sliceSize);

                        var byteNumbers = new Array(slice.length);
                        for (var i = 0; i < slice.length; i++) {
                            byteNumbers[i] = slice.charCodeAt(i);
                        }

                        var byteArray = new Uint8Array(byteNumbers);

                        byteArrays.push(byteArray);
                    }

                    var blob = new Blob(byteArrays, { type: contentType });
                    return blob;
                }

var pdfBlob = base64PdfToBlob(base64Pdf, "application/pdf");
var blobUrl = URL.createObjectURL(pdfBlob);
$scope.pdfDoc = $sce.trustAsResourceUrl(blobUrl);

I then embed the pdf in the html using the following code:

<object data="{{pdfDoc}}" type="application/pdf" width="100%" height="100%"></object>

This works in chrome, firefox, and safari. This does NOT work in Edge or IE11. I feel like I have tried everything with nothing working.

Things I have tried: 1. Playing with the embed and object tags. 2. Uninstalling and reinstalling adobe reader. Messing with the settings and configurations between adobe reader and IE. 3. Changing security settings in IE.

Doing an iFrame, new tab, new window, downloading pdf is not an option. The PDF must be embedded on the current page. Some documentation I am reading seems to state this is NOT possible in Edge but should work in IE.

My machine is Windows 10, 64 bit, IE11, Adobe Acrobat Reader DC 2015.017.20050

Mike
  • 235
  • 2
  • 8
  • 25
  • 1
    Did u ever find an answer to this? I am in a similar situation. Thanks! – sdd Sep 07 '16 at 19:22
  • "Some documentation I am reading seems to state this is NOT possible in Edge but should work in IE" Which document are you referring to? Note that I am having a similar issue, but it has nothing to do with whether the file ends up being embedded or shown in a new window; the response is simply being totally discarded: http://stackoverflow.com/questions/41929282/edge-browser-appears-to-discard-response-payload – Dave Nottage Jan 30 '17 at 06:05

1 Answers1

0

URL.createObjectURL() is not compatible with IE11. The Mozilla docs state that this function is compatible starting with IE12, though.

I do not believe that it is possible to embed the inline blob data representing a PDF in IE11 or Edge. There is a separate function for handling blobs in IE called msSaveOrOpenBlob, but this has the drawback of prompting the user if they want to save or open the file.

See also: Open links made by createObjectURL in IE11

vsahu
  • 170
  • 2
  • 6