Android - How to get highlighted text and its coordinates?

Skip to first unread message

Zeeshan Zakaria

Jan 28, 2015, 1:37:27 PM1/28/15

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() {
            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.


Zeeshan A Zakaria

Shirley Gong

Jan 28, 2015, 6:58:27 PM1/28/15
Hi Zeeshan,

The best place to get started is 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

Zeeshan Zakaria

Jan 29, 2015, 2:27:37 PM1/29/15
Thanks, this was very helpful.
Reply all
Reply to author
0 new messages