title: Decode weird characters by pdf.js
body: <p>I'm playing with pdf.js to convert pdf into text. I noticed some weird characters are displayed, but only in the HTML.</p>
  
  <p>When they are rendered, the correct content appears (human readable text).</p>
  
  <p>However, if I use <code>innerHTML</code> to get the content, I get weird stuff.</p>
  
  <blockquote>
    <p><a href="https://i.stack.imgur.com/n1WgA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/n1WgA.png" alt=""></a></p>
  </blockquote>
  
  <p>The part of code generating this HTML is taken from <a href="http://git.macropus.org/2011/11/pdftotext/" rel="nofollow noreferrer">here</a>, and is:</p>
  
  <pre><code>this.pdfToText = function(data) {
     var div = document.getElementById('viewer');
  
     // render the first pages
     var pdf = new PDFJS.PDFDoc(data);
     var total = pdf.numPages;
  
     for (i = 1; i &lt;= total; i++) {
         var page = pdf.getPage(i);
  
         var canvas = document.createElement('canvas');
         document.body.appendChild(canvas);
         canvas.id = 'page' + i;
         canvas.mozOpaque = true;
         div.appendChild(canvas);
  
         canvas.width = page.width;
         canvas.height = page.height;
  
         var context = canvas.getContext('2d');
         context.save();
         context.fillStyle = 'rgb(255, 255, 255)';
         context.fillRect(0, 0, canvas.width, canvas.height);
         context.restore();
  
         self.setMessage("Rendering...");
  
         var textLayer = document.createElement('div');
         textLayer.className = 'textLayer';
         document.body.appendChild(textLayer);
  
         page.startRendering(context, function() {
             if (++self.complete == total) {
                 self.setMessage("Finished rendering. Extracting text...");
  
                 window.setTimeout(function() {
                     var layers = [];
                     var nodes = document.querySelectorAll(".textLayer &gt; div");
                     for (var j = 0; j &lt; nodes.length; j++) {
                         layers.push(nodes[j].textContent + "\n");
                     }
                     self.sendOutput(layers.join("\n"));
  
                     self.setMessage("Done!");
                 }, 1000);
             }
         }, textLayer);
     }
  };
  </code></pre>
  
  <p>How to decode these characters into human readable text and store the value into a variable?</p>