Testing AnnotationOnChanged Events

PDF.js Express Viewer

PDF.js Express Version
8.4

Detailed description of issue

  • How can I trigger onAnnotationChange (modify) events programatically?
    myStamp.setWidth(80);
    Does not seem to work?

  • How can i find the mouse x, y location for a stamp for user mouse events?

Hi there,

You can trigger a modify annotationChanged events like this:

annotationManager.trigger('annotationChanged', [[annotation], 'modify', {}]);

To find the mouse location when a stamp annotation is added, you can use the annotation’s X,Y properties, i.e.:

annotationManager.addEventListener('annotationChanged', (annotations, action) => {
    if (action === 'add' && annotations[0] instanceof Core.Annotations.StampAnnotation){
    console.log(annotations[0].X, annotations[0].Y)
    }
})

If you just need coordinates of the user’s mouse on the documentViewer, please use mouseMove event API:
https://pdfjs.express/api/Core.DocumentViewer.html#event:mouseMove

best regards,
Kevin