javascript - Embed PDF Byte Data in HTML -


this should working, seems missing something.

i have pdf file on local drive. chrome , other browsers can't local url since it's sandboxed, have servlet pulling data local drive , sending through ajax call web client. i'm not getting errors, , seems pdf viewer loading, file won't display. encoding ahead of time, still won't work. display numerous approaches below, won't include servlet code since seems working.

attempt 1:

function embedfile(){     $.get("filegetter", function(pdftext){          var base64encodedpdf = b64encodeunicode(pdftext);         $("#embedholder").append("<object id='embedder' width='80%' height='600px'><embed width=100% height=100%"                                      + ' type="application/pdf"'                                      + ' src="data:application/pdf;base64,'                                      + base64encodedpdf                                      + "></embed></object>");              });         }   function b64encodeunicode(str) {      return btoa(encodeuricomponent(str).replace(/%([0-9a-f]{2})/g, function(match, p1) {                 return string.fromcharcode('0x' + p1);             }));         } 

attempt 2:

function embedfile(){     $.get("filegetter", function(pdftext){          var base64encodedpdf = b64encodeunicode(pdftext);         var obj = $('<object id="repobjid" type="application/pdf" width="100%" height="600" border="2"></object>');          obj.attr('data',base64encodedpdf);          var embed = $('<embed type="application/pdf"></embed>');          embed.attr('src',base64encodedpdf);          $('#repobjid').append(embed);          $("#docholder").html(obj);     }  function b64encodeunicode(str) {     return btoa(encodeuricomponent(str).replace(/%([0-9a-f]{2})/g,               function(match, p1) {                 return string.fromcharcode('0x' + p1);             })); }     


Comments