Mithun
Mithun

Reputation: 265

Display pdf from base64 data

I am trying to make preview from base64 data . Here it works for any base64 image but if I use base64 pdf then it shows plugin is not supported . Here is my code . There is a post which closely similar but did not meet up my expectation.

if(response.responseCode == 1)
{
  $("#image-info-content").html('<object data="'+response.data+'"></object>');
  $('#image-modal').modal();
}

I also tried with type="application/pdf" . Still it's not working. Though I don't want this because there might be image or pdf file. Thanks in advance

response.data like here data:application/pdf;base64,JVBERi0xLjMKJeLjz9MKMSAwIG9iago8.......

Upvotes: 1

Views: 3262

Answers (1)

berrak
berrak

Reputation: 68

With this way we can open the pdf in a new tab. i found this in somewhere, but i don't remember exactly where

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);

Upvotes: 2

Related Questions