Android - How to get highlighted text and its coordinates?

68 views
Skip to first unread message

Zeeshan Zakaria

unread,
Jan 28, 2015, 1:37:27 PM1/28/15
to pdfne...@googlegroups.com
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

Shirley Gong

unread,
Jan 28, 2015, 6:58:27 PM1/28/15
to pdfne...@googlegroups.com
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

Zeeshan Zakaria

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