title: PDFJS is not defined in pdf.worker.js (Backbone+Marionette+pdf.js)
body: <p>I want to render a PDF inside a Backbone.js/Marionette View with pdf.js, but PDFJS is not defined <strong>in pdf.worker.js</strong>. It is however defined in the Backbone View itself and also accessible via the console.</p>
  
  <p><em>This is the code for the View:</em></p>
  
  <pre><code>module.exports = PDFView = Marionette.ItemView.extend({
      template: require('../../../templates/pdf_frame.hbs'),
      onRender: function(){
          var PDF_PATH = '../../pdf/websummitpitch.pdf';
          var PAGE_NUMBER = 1;
          var PAGE_SCALE = 1.5;
          var SVG_NS = 'http://www.w3.org/2000/svg';
  
          if (PDFJS) {
              console.log("PDFJS is loaded in Backbone View");
          } else {
              console.log("PDFJS is NOT loaded in Backbone View");
          }
  
          PDFJS.workerSrc = "/js/pdf.worker.js";
          console.log("workerSrc is set to ", PDFJS.workerSrc);
  
          // Loading document and page text content
          PDFJS.getDocument({url: PDF_PATH}).then(function (pdfDocument) {
              console.log("get document");
  
              pdfDocument.getPage(PAGE_NUMBER).then(function (page) {
                  console.log("get page");
  
                  var viewport = page.getViewport(PAGE_SCALE);
                  page.getTextContent().then(function (textContent) {
                      // building SVG and adding that to the DOM
                      var svg = this.buildSVG(viewport, textContent);
  
                      // render svg in &lt;canvas id="render"&gt; in template
                      document.getElementById('render').appendChild(svg);
                  });
              });
          });
      },
      buildSVG: function(viewport, textContent) {
          // Building SVG with size of the viewport (for simplicity)
          var svg = document.createElementNS(SVG_NS, 'svg:svg');
          svg.setAttribute('width', viewport.width + 'px');
          svg.setAttribute('height', viewport.height + 'px');
          // items are transformed to have 1px font size
          svg.setAttribute('font-size', 1);
  
          // processing all items
          textContent.items.forEach(function (textItem) {
              // we have to take in account viewport transform, which incudes scale,
              // rotation and Y-axis flip, and not forgetting to flip text.
              var tx = PDFJS.Util.transform(
                  PDFJS.Util.transform(viewport.transform, textItem.transform),
                  [1, 0, 0, -1, 0, 0]);
              var style = textContent.styles[textItem.fontName];
              // adding text element
              var text = document.createElementNS(SVG_NS, 'svg:text');
              text.setAttribute('transform', 'matrix(' + tx.join(' ') + ')');
              text.setAttribute('font-family', style.fontFamily);
              text.textContent = textItem.str;
              svg.appendChild(text);
          });
          return svg;
      }
  });
  </code></pre>
  
  <p><em>This is the console output:</em>
  <img src="https://i.stack.imgur.com/tu0EQ.png" alt="console output">
  The blue is console input, so PDFJS is accessible via the console.</p>
  
  <p><em>This is where the reference error occurs (in pdf.worker.js):</em></p>
  
  <pre><code>PDFJS.version = '1.0.233';
  </code></pre>
  
  <p>It is one of the very first lines, where the version number is set. However PDFJS seems to be undefined.</p>
  
  <p><em>This is my question:</em></p>
  
  <p>Why is it not defined? How should I fix this?</p>