Search code examples
javascripthtmlpdfbase64embed

how to display base64 encoded pdf?


I have to display base64 pdf in new tab. I am using below code

 var windo = window.open("", "");  
 var objbuilder = '';
 objbuilder += ('<embed width=\'100%\' height=\'100%\'  src="data:application/pdf;base64,');
 objbuilder += (fileData);
 objbuilder += ('" type="application/pdf" />');
 windo.document.write(objbuilder); 

It is working in FireFox and not working in Chrome and IE. I even tried with tag, but same output, working in FF but not in Chrome and IE.

I look into below JsFiddles, for which are working in FF but not in Chrome,

http://jsfiddle.net/yLx2W/

http://jsfiddle.net/yLx2W/1/

My Chrome version is : Version 54.0.2840.99 m

FireFox Version : 49.0.2

How can this be done?


Solution

  • It should work with Chrome you can use

    <iframe src="data:base64...">

    <object data="data:base64...">

    I've faced the same issue with IE: it's impossible to display a pdf with a base64 string.

    I had to generate temporary files on the server to display them with IE he only display existing file by using a path.

    You still can use JS library to display your pdf like PDF.js.