0

I have a MVC controller that will send back the base64 pdf string to the client via an ajax call.

The following line will display the pdf in a separate window for Chrome and FF.

<a href=data:application/pdf;base64," + data.PDFResult + " download title='Download pdf document' />

This will not work in IE and from what I read it doesn't appear to be supported.

So. Instead of displaying the PDF in a new window how can I make the user download the PDF instead?

UPDATE:

  • Trying to send byte[] back to client via AJAX...

I changed JS to:

var pdfWin = window.open("data:application/octet-stream, " + escape(data), '', 'height=650,width=840');

and my controller to:

[HttpPost]
        public byte[] GetPDFc(MyObject myData)
        {
            var pdfBytes = MethodToGetPDF(myData);
            return (pdfBytes);
        }
John Doe
  • 3,053
  • 17
  • 48
  • 75

1 Answers1

1

IE does not support download attribute

Instead serve the file from server using application/octet-stream with a filename

Force PDF download 'only' in Internet Explorer


The download attribute should work on Edge browser -

http://caniuse.com/#feat=download

enter image description here

Community
  • 1
  • 1
mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • We are using IE11 not edge. I would prefer not to store the PDF if I can avoid it. – John Doe Dec 15 '16 at 14:59
  • Then the answer is not possible – mplungjan Dec 15 '16 at 15:00
  • Is it possible just to send the byte[] back instead? In my case I'd rather not save the document to disk just to allow the user to view/download. I will have high traffic with many different documents and I would not prefer to have to manage deleting all of these copies. – John Doe Dec 15 '16 at 18:45
  • Why save? You can stream - you can even send your string back to the server and load the stream – mplungjan Dec 15 '16 at 19:24
  • I'm confused then. Yes the whole point is that the server is sending back a base64 string to the client. From there I am either trying to display(in a new window) or force the client to download the file. It appears part of my heartburn with IE is because I'm using an ajax post call to get the pdf string. – John Doe Dec 15 '16 at 19:29
  • Yes so instead for IE send the binary with the octet-stream mime – mplungjan Dec 15 '16 at 19:30