close

how to display base64 encoded pdf?

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn how to display base64 encoded pdf? in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

how to display base64 encoded pdf ?

  1. how to display base64 encoded pdf ?

    to display base64 encoded pdf 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.

  2. how to display base64 encoded pdf ?

    to display base64 encoded pdf 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.

Method 1

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.

Method 2

for those who still can’t do it, i found this in someone else answer, 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);

this way we open the pdf in a new tab.

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment