Search code examples
javascriptpdfiframebase64internet-explorer-11

pdf not getting embedded in html IE11


I want to embed base64 encoded string of pdf into an html template. <iframe src="data:application/pdf;base64, encodeURI(pdfstring)"></iframe> This works fine in chrome and edge but showing blank page in IE 11.I do not want to download it.Is there a fix for IE11


Solution

  • It doesn't work because IE doesn't support iframe with data url as src attribute. You could check it in caniuse. It shows that the support is limited to images and linked resources like CSS or JS in IE. Please also check this documentation:

    Data URIs are supported only for the following elements and/or attributes.

    • object (images only)
    • img
    • input type=image
    • link
    • CSS declarations that accept a URL, such as background, backgroundImage, and so on.

    You can only do what like the accepted answer says:

    The only workaround for this is to return your PDF content from a HTTP/HTTPS or FTP URI and use that as the source of the IFRAME.