0

I have the below in my HTML,

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script>
      function displayStream(bytestream){
      var data = btoa(bytestream);
      console.log(data);
         var obj ='<object type="application/pdf" width="100%" height="100%" border="2" class="pdfObject" data="data:application/pdf;base64,'+data+'" ></object>'; 
          $('#divContainer').append(obj);  
        }
        
    </script>
    <title>Development </title>
  </head>
  <body>
    <p id='output'> Below is the PDF </p>
    
   <div id="divContainer">
    
   </div>
  </body>
</html>

I am getting the byte stream array in my ajax call and when I call the displayStream method it throws the below error in the developer console.

enter image description here

After converting the byte[] still, it is throwing the below error.

enter image description here

Can anyone advice how to display the PDF byte[] in an HTML page as a PDF within the DIV using javascript.

Aravind
  • 1,145
  • 6
  • 18
  • 44
  • You use the base64 uri scheme but are not concatenating base64 ... Those negative values look odd, what exactly is bytestream? – Alex K. Nov 24 '17 at 11:34
  • The `byte[]` is binary data. For it to work in the `data` attribute you need to convert it to a base64 encoded string. See the duplicate for guidance on how to do that – Rory McCrossan Nov 24 '17 at 11:35
  • @RoryMcCrossan Hi Roy, I have converted to base64 as per the guidance, still, I am facing the issue. – Aravind Nov 24 '17 at 11:50

0 Answers0