MuPDF WebViewer can listen for the following events:

  • acroFieldChange
  • actionHistoryChange
  • annotationCreate
  • annotationModify
  • annotationRemove
  • annotationSelectionChange
  • annotationToolChange
  • currentPageIndexChange
  • currentReadingPageChange
  • customContextMenuExecute
  • documentDownload
  • documentSave
  • dragToolChange
  • keydown
  • keyup
  • mousedown
  • mouseup
  • pointerdown
  • pointerup
  • redactionCreate
  • redactionModify
  • redactionRemove
  • scaleChange
  • scrollPositionChange
  • sideViewClose
  • sideViewOpen
  • signatureCancel
  • signatureInsert
  • textSearchStart
  • tsaVerify
  • widgetMousedown

In order to register a listener just use the mupdf.addEventListener method.

Examples

Page Change

mupdf.addEventListener('currentPageIndexChange', (e) => {
  console.log(Object.keys(e.data));
  console.log(e.data.currentPageIndex);
});

Key Events

// Listen for a key down
mupdf.addEventListener('keydown', keyDown);

function keyDown(e) {

    console.log(Object.keys(e.data));
    
    for (var i in e.data) {
        console.log(e.data[i]);
    }

    console.log("Keycode="+e.data.event.keyCode);
}

Pointer Events

// Listen for a pointer down
mupdf.addEventListener('pointerdown', pointerDown);

function pointerDown(e) {

    console.log(Object.keys(e.data));

    for (var i in e.data) {
        console.log(e.data[i]);
    }

    console.log("clientX="+e.data.event.clientX);
}