How do I jump to a specific location on a page?

79 views
Skip to first unread message

Justin Jung

unread,
Nov 7, 2017, 1:50:21 PM11/7/17
to PDFTron WebViewer
Q: How do I jump to a specific location on a page? For example, I want to scroll to page 42 and 65% down the page!

A: You can add the following function to config.js:

var displayPageLocation = function(pageNumber, vpercent, hpercent) {
  var docViewer = readerControl.docViewer;

  if (docViewer.getCurrentPage() !== pageNumber) {
    docViewer.setCurrentPage(pageNumber);
  }
  var pageWidth = docViewer.getPageWidth(pageNumber - 1);
  var pageHeight = docViewer.getPageHeight(pageNumber - 1);

  var hpos = pageWidth * hpercent / 100;
  var vpos = pageHeight * vpercent / 100;

  var wPt = docViewer.getDisplayModeManager().getDisplayMode().pageToWindow({
    x: hpos > pageWidth ? 0 : Math.max(hpos, 0),
    y: vpos > pageHeight ? 0 : Math.max(vpos, 0)
  }, pageNumber - 1);

  var scrollView = $('#DocumentViewer');
  var scrollViewOffset = scrollView.offset();

  docViewer.scrollTo(wPt.x - scrollViewOffset.left, wPt.y - scrollViewOffset.top);
};

and you can call the function as follows:

displayPageLocation(42, 65, 0);
Reply all
Reply to author
Forward
0 new messages