Put highlighted or selected text from PDF file into textarea or textbox

I am displaying a PDF file.
What I want to acheve is: when user highlights a word or phrase in the PDF, it should be visible in a textarea or textbox.
I am using AngularJS.

This is my javascript code:

    function getSelectionText() {
      var text = "";
      var activeEl = document.activeElement;
      var activeElTagName = activeEl ? activeEl.tagName.toLowerCase() : 
     null;
      if (activeElTagName == "textarea") {
        text = activeEl.value.slice(activeEl.selectionStart, 
        activeEl.selectionEnd);
      } else {
        if (window.getSelection) {
          text = window.getSelection().toString();
        }
      }
      return text;
    }

    document.onmouseup = document.onkeyup = document.onselectionchange = 
      function () {
        document.getElementById("sel").value = getSelectionText();
      }
    ;

This is my HTML code:

<div ng-controller="PDFCtrl">
  <form name=aform>
    <textarea id="sel" rows="5" cols="20"></textarea>
  </form>
  <p>angular pdf to html</p>
  <hr />
  <div id="example1"></div>
  <script src="../Scripts/pdfobject.js"></script>
  <script>PDFObject.embed("/Scripts/Classic.pdf", "#example1");</script>
  <script src="~/AngularControllers/TestController.js"></script>
</div>

When I highlight a word from PDF it should be displayed in textarea.

Source: AngularJS