Mahendra
Mahendra

Reputation: 337

How to use with Base64string PDF data

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

  1. Can you sugest me, how to convert pdf base64 encoded string to image[i'm getting base64 encoded string directly from server]

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

Answers (3)

Asanka
Asanka

Reputation: 618

<embed src="data:application/pdf;base64,BASE_64_STRING" type="application/pdf" width="100%" height="600px" />

Upvotes: 4

hosam hemaily
hosam hemaily

Reputation: 458

why you dont use iframe

<iframe id="framTest" height="100%" width="100%" />
$('#framTest').prop("src", your base64 string);

Upvotes: 0

Saptarshi Dey
Saptarshi Dey

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

Related Questions