title: pdfjs: get raw text from pdf with correct newline/withespace
body: <p>Using <a href="https://mozilla.github.io/pdf.js/" rel="nofollow noreferrer">pdf.js</a>, i have made a simple function for extract the raw text from a pdf:</p>
  
  <pre><code>async getPdfText(path){
  
      const pdf = await PDFJS.getDocument(path);
  
      const pagePromises = [];
      for (let j = 1; j &lt;= pdf.numPages; j++) {
          const page = pdf.getPage(j);
  
          pagePromises.push(page.then((page) =&gt; {
              const textContent = page.getTextContent();
              return textContent.then((text) =&gt; {
                  return text.items.map((s) =&gt;  s.str).join('');
              });
          }));
      }
  
      const texts = await Promise.all(pagePromises);
      return texts.join('');
  }
  
  // usage
  getPdfText("C:\\my.pdf").then((text) =&gt; { console.log(text); });
  </code></pre>
  
  <p>however i can't find a way for extract correctly the new lines, all the text is extracted in only one line.</p>
  
  <p>How extract correctly the text? i want extract the text in the same way as on desktop pc:</p>
  
  <p>Open the pdf (doble click on the file) -> select all text (CTRL + A) -> copy the selected text (CTRL + C) -> paste the copied text (CTRL + V)</p>