title: Javascript download BLOB as PDF
body: <p>I am trying to convert a blob object to a pdf and download it.</p>
  <p>So far I've tried the following:</p>
  <pre><code>var downloadLink = document.createElement('a');
              downloadLink.target = '_blank';
              downloadLink.download = 'name_to_give_saved_file.pdf';
  
              // convert downloaded data to a Blob
              var blob = new Blob([file.$binary], { type: 'application/pdf' });
  
              // create an object URL from the Blob
              var URL = window.URL || window.webkitURL;
              var downloadUrl = URL.createObjectURL(blob);
  
              // set object URL as the anchor's href
              downloadLink.href = downloadUrl;
  
              // append the anchor to document body
              document.body.append(downloadLink);
  
              // fire a click event on the anchor
              downloadLink.click();
  </code></pre>
  <p>The file size seems to be correct, but I cant view it since it seems to be damaged.</p>
  <p>Viewing the PDF inside of my html file works like this:</p>
  <pre><code> $('#test').html('&lt;embed width=100% height=100%'
              + ' type=&quot;application/pdf&quot;'
              + ' src=&quot;data:application/pdf;base64,'
              + escape(file.$binary)
              + '&quot;&gt;&lt;/embed&gt;')
  </code></pre>
  <p>This works without any problems!</p>
  <p>Now to my question... why is one working and the other one isn't?</p>
  <p>Thanks for your help...</p>