title: Render PDF using PDF.JS and AngularJS from byte array
body: <p>I've been following the following links to try to render a byte stream returned from an API to a PDF in browser using PDF.JS:</p>
  
  <ul>
  <li><a href="http://codingcrazy87.blogspot.com/2014/05/view-pdf-files-directly-within-browser.html" rel="nofollow">http://codingcrazy87.blogspot.com/2014/05/view-pdf-files-directly-within-browser.html</a></li>
  <li><a href="https://gist.github.com/fcingolani/3300351" rel="nofollow">https://gist.github.com/fcingolani/3300351</a></li>
  </ul>
  
  <p>Here is the <strong>JavaScript</strong> used to run render. <strong>Note:</strong> <em>stream</em> is a byte array returned from an API.</p>
  
  <pre><code>var file = new Blob([stream], {type: 'application/pdf'});
  var fileURL = URL.createObjectURL(file);
  $scope.renderPDF(fileURL, document.getElementById('pdf-holder'));
  </code></pre>
  
  <p>Here is <strong>$scope.renderPDF</strong>:</p>
  
  <pre><code>$scope.renderPDF = function(url, canvasContainer) {
      var scale= 1.5;  //"zoom" factor for the PDF
  
      function renderPage(page) {
          var viewport = page.getViewport(scale);
          var canvas = document.createElement('canvas');
          var ctx = canvas.getContext('2d');
          var renderContext = {
              canvasContext: ctx,
              viewport: viewport
          };
  
          canvas.height = viewport.height;
          canvas.width = viewport.width;
  
          canvasContainer.appendChild(canvas);
  
          page.render(renderContext);
      }
  
      function renderPages(pdfDoc) {
          for(var num = 1; num &lt;= pdfDoc.numPages; num++)
              pdfDoc.getPage(num).then(renderPage);
      }
  
      PDFJS.disableWorker = true;
      PDFJS.getDocument(url).then(renderPages);
  
  }
  </code></pre>
  
  <p>Here is the <strong>HTML</strong> in my template page:</p>
  
  <pre><code>&lt;script type="text/javascript" src="https://cdn.rawgit.com/mozilla/pdf.js/gh-pages/build/pdf.js"&gt;&lt;/script&gt;
  
  &lt;div id="pdf-holder"&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>When the code runs</p>
  
  <pre><code>PDFJS.getDocument(url).then(renderPages);
  </code></pre>
  
  <p>I get a 404 Not Found error on <em>worker.js</em>, which makes sense because I'm following these examples and disabling worker so I shouldn't need it. Does anyone have any advice or an easy way around this that I can render a pdf in browser from a byte stream?</p>