Document jumps back to first page

109 views
Skip to first unread message

Matt Parizeau

unread,
Dec 19, 2018, 8:28:25 PM12/19/18
to pdfnet-w...@googlegroups.com
Q:

We are programmatically setting the current page in WebViewer on the documentLoaded event but after a second WebViewer jumps back to the first page on some files. Why is happening and how can I fix it?

A:

This is likely because the document has an "open" action that sets the current page to the first page. WebViewer includes the action as part of the XFDF data and parses this asynchronously so there might be a bit of a delay before the open action is triggered.

To work around this what you can do is ignore any GoTo open actions that are triggered on the document. You can add the following to your config file:

var onTriggered = Actions.GoTo.prototype.onTriggered;
Actions.GoTo.prototype.onTriggered = function(target, event) {
 
if (target === readerControl.docViewer.getDocument() && event.name === 'Open') {
   
return;
 
}

  onTriggered
.apply(this, arguments);
};

Matt Parizeau

unread,
Dec 18, 2020, 8:16:01 PM12/18/20
to PDFTron WebViewer
For the latest versions of WebViewer the code is similar but you can access Actions and docViewer from the instance object.

const { Actions, docViewer } = instance;
const onTriggered = Actions.GoTo.prototype.onTriggered;
Actions.GoTo.prototype.onTriggered = function(target, event) {
  if (target === docViewer.getDocument() && event.name === 'Open') {
    return;
  }

  onTriggered.apply(this, arguments);
};  

Reply all
Reply to author
Forward
0 new messages