title: Failed to load PDF document javascript
body: <p>I am trying to generate simple PDF file using below code but failing with error : "Failed to load PDF document":</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(['downloadedFile'], { 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>Tried to follow many existing answers(e.g. <a href="https://stackoverflow.com/questions/12876000/how-to-build-pdf-file-from-binary-string-returned-from-a-web-service-using-javas?answertab=active#tab-top">How to build PDF file from binary string returned from a web-service using javascript</a>) but did not get any solution yet. Please help.
  Thanks in advance :)</p>