title: Retrieving number of pages of a PDF using PDF.JS fails with return
body: <p>I don't understand the following. Maybe I am missing some really stupid issue here... can anybody solve it? Thanks in advance.</p>
  
  <p>I have this code in Javascript:</p>
  
  <pre><code>function funcLeNrPaginasPDF(strCaminhoPDF) {
      var objLivrariaPDF = window['pdfjs-dist/build/pdf'];
      var objDocumentoPDF = null; 
  
      objLivrariaPDF.workerSrc = '/pdfjs/pdf.worker.js';
  
      // strCaminhoPDF var contains the pdf doc: "documento.pdf"
  
      var oprCarregaPDF = objLivrariaPDF.getDocument(strCaminhoPDF);
      oprCarregaPDF.promise.then(function(objDocumentoPDF) { document.getElementById('nr_paginas').textContent = objDocumentoPDF.numPages; });
  </code></pre>
  
  <p>It works like a charm, thus, if I change document.getElementById... and put</p>
  
  <pre><code>alert (objDocumentoPDF.numPages);
  </code></pre>
  
  <p>it works as well... However if I place a "return" the function returns me an <em>undefined</em> variable content. Like this:</p>
  
  <pre><code>oprCarregaPDF.promise.then(function(objDocumentoPDF) { return objDocumentoPDF.numPages; });
  </code></pre>
  
  <p>Any thoughts why? I need a variable to hold the number of pages.
  Regards.</p>