title: Use PDFJS DefaultTextLayerFactory and DefaultAnnotationLayerFactory from Angular4
body: <p>I have a web app written in Angular4 using typescript and it has been working well for me. I now try to change is to use the annotation layers and I can't figure out how to do that. I have changed my code to work like the pageviewer example.</p>
  
  <p>I import pdf.js like this:</p>
  
  <pre><code>import * as PDFJS from 'pdfjs-dist';
  </code></pre>
  
  <p>I load the document like this:</p>
  
  <pre><code>this.loadingTask = PDFJS.getDocument(url);
  this.loadingTask.onProgress = progress =&gt; this.downloadProgress = (progress.loaded / fileSize) * 80;
  this.pdf = await this.loadingTask;
  </code></pre>
  
  <p>and then I render it like in the pageviewer example:</p>
  
  <pre><code>// Get size of current PDF page
  const page = await this.pdf.getPage(currentPage);
  let viewport = page.getViewport(1);
  
  // Calculate the scale
  let scale = 1;
  if (zoomWidth) {
      scale = windowWidth / viewport.width;
  } else {
      scale = Math.min(windowWidth / viewport.width, windowHeight / viewport.height);
  }
  
  // Creating the page view with default parameters.
  var pdfPageView = new PDFJS.PDFPageView({
      container: container,
      id: currentPage,
      scale: scale,
      defaultViewport: page.getViewport(scale),
      // We can enable text/annotations layers, if needed
      textLayerFactory: new PDFJS.DefaultTextLayerFactory(),
      annotationLayerFactory: new PDFJS.DefaultAnnotationLayerFactory()
  });
  // Associates the actual page with the view, and drawing it
  pdfPageView.setPdfPage(page);
  return pdfPageView.draw();
  </code></pre>
  
  <p>When I run this I get det following error in the Chrome console:</p>
  
  <pre><code>ERROR Error: Uncaught (in promise): TypeError: __WEBPACK_IMPORTED_MODULE_1_pdfjs_dist__.DefaultTextLayerFactory is not a constructor
  TypeError: __WEBPACK_IMPORTED_MODULE_1_pdfjs_dist__.DefaultTextLayerFactory is not a constructor
  </code></pre>
  
  <p>If I comment out DefaultTextLayerFactory and DefaultAnnotationLayerFactory I get a similar error on PDFPageView.</p>
  
  <p>What am I doing wrong?</p>