"pdf highlighter" Code Answer's

You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "pdf highlighter" answered properly. Developers are finding an appropriate answer about pdf highlighter related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like pdf highlighter. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on pdf highlighter. 

pdf highlighter

By Xenophobic XenomorphXenophobic Xenomorph on May 11, 2021
function getSelectionCoords() {
    var pdfViewer = window.appPdfViewer;    
    var pageIndex = pdfViewer.currentPageNumber - 1; 
    var page = pdfViewer.getPageView(pageIndex);
    var pageRect = page.canvas.getClientRects()[0];
    var selectionRects = window.getSelection().getRangeAt(0).getClientRects();
    var viewport = page.viewport;
    var selectionRectsList = Object.values(selectionRects);
    var selected = selectionRectsList.map(function (r) {
      return viewport.convertToPdfPoint(r.left - pageRect.x, r.top - pageRect.y).concat(
         viewport.convertToPdfPoint(r.right - pageRect.x, r.bottom - pageRect.y)); 
    });
    return {page: pageIndex, coords: selected};
}



function showHighlight() {
    var selected = getSelectionCoords();
    var pageIndex = selected.page; 
    var pdfViewer = window.appPdfViewer;  
    var page = pdfViewer.getPageView(pageIndex);
    var pageElement = page.canvas.parentElement;
    var viewport = page.viewport;

    selected.coords.forEach(function (rect) {

      // Individual Seletions...
      var x1 = Math.min(bounds[0], bounds[2]);
      var y1 = Math.min(bounds[1], bounds[3]);
      var width =  Math.abs(bounds[0] - bounds[2]);
      var hight = Math.abs(bounds[1] - bounds[3]);
      var el = createRectDiv([x1, y1, width, hight]);
      pageElement.appendChild(el);

    });
   
}

function createRectDiv(boundBox){
    var randomColor = Math.floor(Math.random()*16777215).toString(16);
    console.log(randomColor);
    var el = document.createElement('div');
    el.setAttribute('class', 'hiDiv')
    el.setAttribute('style', 'position: absolute; background-color: #'+randomColor+'; opacity: 0.5;' + 
    'left:' + boundBox[0] + 'px; top:' + boundBox[1] + 'px;' +
    'width:' + boundBox[2] + 'px; height:' + boundBox[3] + 'px;');
    return el;
}


window.addEventListener('mouseup', function() {

    var length = window.getSelection().toString().length;
    if(length > 0){
        showHighlight();
    }else{
        // Clear All ?!
    }
  console.log();
});



Source: gist.github.com

Add Comment

0

All those coders who are working on the Whatever based application and are stuck on pdf highlighter can get a collection of related answers to their query. Programmers need to enter their query on pdf highlighter related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about pdf highlighter for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of pdf highlighter while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "pdf highlighter". Visit this developer's friendly online web community, CodeProZone, and get your queries like pdf highlighter resolved professionally and stay updated to the latest Whatever updates. 

Whatever answers related to "pdf highlighter"

View All Whatever queries

Whatever queries related to "pdf highlighter"

Browse Other Code Languages

CodeProZone