How to display base64 encoded pdf file?

I need to display base64 pdf in a new tab. I use 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 works in FireFox and does not work in Chrome and IE. I even tried with a tag, but the same output works in FF, but not in Chrome and IE.

I look below JsFiddles, for which they work in FF, but not in Chrome,

http://jsfiddle.net/yLx2W/

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

My Chrome Version: Version 54.0.2840.99 m

FireFox Version: 49.0.2

Does anyone have any ideas please share.

Thanks at Advance

+12
javascript html base64 pdf embed
source share
3 answers

It should work with Chrome, which you can use

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

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

I have the same problem with IE : it is not possible to display a PDF with a base64 string.

I had to generate temporary files on the server to display them using IE, it only displayed existing files using the path.

You can still use the JS library to display your PDF- PDF.js for example PDF.js

+5
source share

for those who still cannot do this, I found this from someone else, but I don’t remember who ...

 var objbuilder = ''; objbuilder += ('<object width="100%" height="100%" data="data:application/pdf;base64,'); objbuilder += (myBase64string); objbuilder += ('" type="application/pdf" class="internal">'); objbuilder += ('<embed src="data:application/pdf;base64,'); objbuilder += (myBase64string); objbuilder += ('" type="application/pdf" />'); objbuilder += ('</object>'); var win = window.open("#","_blank"); var title = "my tab title"; win.document.write('<html><title>'+ title +'</title><body style="margin-top: 0px; margin-left: 0px; margin-right: 0px; margin-bottom: 0px;">'); win.document.write(objbuilder); win.document.write('</body></html>'); layer = jQuery(win.document); 

thus we open pdf in a new tab.

+7
source share
0
source share

All Articles