Android - How to get highlighted text and its coordinates?

Hello,

After selecting some text in a document, I am trying to get the Rect or Quad info along with the highlighted text, so I could save it in a separate file, but couldn’t find a way to do it so far.

My ToolManager is: pdftron.PDF.Tools.ToolManager tm = new pdftron.PDF.Tools.ToolManager(mPDFView);

And then I have two listeners, though I don’t know which one to use and if I am doing it right at all:

tm.setToolChangedListener(new ToolManager.ToolChangedListener() {
@Override
public void toolChanged(ToolManager.Tool newTool, ToolManager.Tool oldTool) {
Log.v(“toolChanged”, “toolChanged”);
}
});

tm.setPreToolManagerListener(new ToolManager.PreToolManagerListener() { …

I saw another post where a C++ example was given, but I couldn’t replicate it for Android.

Any pointers to help me do this task would be highly appreciated.

Thanks

Zeeshan A Zakaria

Hi Zeeshan,

The best place to get started is TextSelect.java in PDFViewCtrlTools project.
TextSelect tool tells you how text is selected and how to work with selected text.

To get the text, you will need to use PDFViewCtrl.getSelection.
For details, take a look at “onQuickMenuClicked” “if (str.equals(“copy”))…” block.

To obtain the Rect, take a look at “onQuickMenuClicked”, the next if block after “copy”.

Hope this helps!

Best Regards,
Shirley Gong

Thanks, this was very helpful.