Reputation: 337
I have base64 string of the pdf file(Gmail PDF attachments), i am getting the base64 encoded from the server directly,now i need to convert this base64 to image to display the pdf in next tab of the browser.
I'm using the below code, var pdfAsDataUri = "data:image/png;base64,"+file; window.open(pdfAsDataUri); * the new tab is open and is not displaying the pdf
Note: Please find the below image, if i click on that green marked icon, the pdf should open in new tab.enter image description here
Upvotes: 5
Views: 17363
Reputation: 618
<embed src="data:application/pdf;base64,BASE_64_STRING" type="application/pdf" width="100%" height="600px" />
Upvotes: 4
Reputation: 458
why you dont use iframe
<iframe id="framTest" height="100%" width="100%" />
$('#framTest').prop("src", your base64 string);
Upvotes: 0
Reputation: 366
You can try making an Image
object. Then in the src
put the base64.
var myImage = new Image();
myImage.src="data:image/png;base64,"+file;
Upvotes: 4