title: Convert RTF document to plain text
body: <p>I have a file input that gets the text from a file uploaded by a file input.
  It works fine with plain text but when I try and upload a RTF document it comes up with a load of garbled text.</p>
  
  <p>I was wondering if I could convert the RTF document to a plain text file before displaying it on the screen.</p>
  
  <p>Here is my code.</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;input type="file" id="fileinput" /&gt;
  &lt;pre id="texts"&gt;&lt;/pre&gt;
  &lt;script type="text/javascript"&gt;
    function readSingleFile(evt) {
      //Retrieve the first (and only!) File from the FileList object
      var f = evt.target.files[0]; 
  
      if (f) {
        var r = new FileReader();
        r.onload = function(e) { 
            var contents = e.target.result;
                document.getElementById("texts").innerHTML = contents;
        }
        r.readAsText(f);
      } else { 
        alert("Failed to load file");
      }
    }
  
    document.getElementById('fileinput').addEventListener('change', readSingleFile, false);
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I don't mind about keeping images or styles, I just want to display the text.</p>
  
  <p>Thanks in advance.</p>