Customizing text selection behavior

43 views
Skip to first unread message

Matt Parizeau

unread,
May 26, 2014, 5:42:26 PM5/26/14
to pdfnet-w...@googlegroups.com
Q:

1)      I’m currently working with the ‘textSelected’ event and can’t determine how I can know what page in the document the text is being selected on. It’s very common for more than one page to be visible so ‘currentpage’ is not a valid variable to check. How can I go about getting this from the event?

2)      I was also wondering how to prevent multiple pages from being selected. I noticed your demo prevents the user from moving the highlight action to two pages (https://www.pdftron.com/webviewer/demo/samples/universal/) How can I mimic this restriction without using the highlight tool?

A:

You should be able to achieve this by overriding the text select tool. You could put code like the following in a config file:
var oldTextSelected = Tools.TextSelectTool.prototype.textSelected;

Tools.TextSelectTool.prototype.textSelected = function(pageIndex, quads, text) {
   
// put your custom code here
    oldTextSelected
.apply(this, arguments);
};

If you just use the code above then this isn't changing anything, but now you have access to the page index for 1).

For 2) you could similarly override the mouseLeftDown/Up functions and keep track of when a selection starts/ends and don't call oldTextSelected when the page index isn't the same as the starting value.
Reply all
Reply to author
Forward
0 new messages