[WebViewer] Attempting to bind to textSelected event of Text HighlightTool

87 views
Skip to first unread message

Chris Hine

unread,
Dec 12, 2014, 3:03:27 PM12/12/14
to pdfnet-w...@googlegroups.com
Hi,

I'm seeking to get access to the event data when a user highlights text and perhaps I'm not going about about it the intended way.

From the documentation I see the TextAnnotationCreateTool has a 'textSelected' event by way of TextTool. Within a config.js I see that readerControl has a toolModeMap with what looks like tools and I'm able to programmaticly set the mode to text highlight using the AnnotationCreateTextHighlight tool from the map.

But this never seems to fire:

$(function () {
    readerControl.toolModeMap['AnnotationCreateTextHighlight']
        .bind('textSelected', function (quads, text) {
                console.log('textSelected');
                console.log(quads);
                console.log(text);
            });
});

I note that the names of the tools in the map to explicitly correspond to the tools listed in the documentation, am I missing something?

Thanks,
Chris

Matt Parizeau

unread,
Dec 12, 2014, 7:54:00 PM12/12/14
to pdfnet-w...@googlegroups.com
Hi Chris,

It looks like this is improperly documented.. thanks for pointing this out! textSelected is actually a function on the tool that you should override. For example:

var highlightTextSelected = Tools.TextHighlightCreateTool.prototype.textSelected;
Tools.TextHighlightCreateTool.prototype.textSelected = function(pageIndex, quads, text) {
    highlightTextSelected
.apply(this, arguments);
   
// get the quads into a usable format
    quads
= quads.map(function(q) {
       
return q.GetPoints();
   
});
};

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Chris Hine

unread,
Dec 15, 2014, 11:12:01 AM12/15/14
to pdfnet-w...@googlegroups.com
Hi Matt,

Thanks! That certainly clears that up why I couldn't get it to trigger.

I am similarly interested in 'mouseLeftUp'. However I don't see it being triggered either:

    readerControl.toolModeMap['AnnotationCreateTextHighlight'].bind('mouseLeftUp', function (e) {
        console.log('mouseLeftUp MAP');
    });

Is it intended that working with the tools be done via the tools via the map in readerControl or via the Tools namespace?

This however also yields no results:

Tools.TextHighlightCreateTool.bind('mouseLeftUp', function (e) {
    console.log('mouseLeftUp TOOL');
});

Thanks, 
Chris

Matt Parizeau

unread,
Dec 15, 2014, 6:24:06 PM12/15/14
to pdfnet-w...@googlegroups.com
Hi Chris,

You'll want to do the same thing with all of the "events" (that aren't really events) on the tools. So for mouseLeftUp:
var mouseLeftUp = Tools.TextHighlightCreateTool.prototype.mouseLeftUp;
Tools.TextHighlightCreateTool.prototype.mouseLeftUp = function(e) {
    mouseLeftUp
.apply(this, arguments);
   
// ...
};

It's recommended that you just refer to the tools from the Tools namespace. The tool mode map is mainly for mapping between the WebViewer.js tool names (shared between HTML5, Silverlight and Flash) and the actual HTML5 Tool classes.

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Chris Hine

unread,
Dec 17, 2014, 3:31:00 PM12/17/14
to pdfnet-w...@googlegroups.com
Ah, of course. Fool me twice...... I will no longer take for granted that something stated as being an event actually is. :)
Reply all
Reply to author
Forward
0 new messages