Reputation: 94
How to get the copy and paste selection in MuPdf.
I want to get like this below image.
Upvotes: 1
Views: 1355
Reputation: 767
Let me start with my standard spiel...
MuPDF is, at heart, a portable C library for opening/manipulating/rendering PDF (and other) file formats. It provides a C level API. Provided with the MuPDF library are various tools (such as PDF manipulation/rendering utilities, and example viewers for various different platforms).
As far as possible all the 'smarts' for these tools are encapsulated within the core library, and the tools themselves are thin veneers over this core functionality.
The Android viewer is one such example of this. The UI is written in Java, and it calls down to the core using a set of JNI functions to do all the file opening/page selection/rendering etc.
Now onto your question:
The logic for text selection already exists within MuPDF. Open a PDF, then from the top bar select the rightmost icon "(v)" to see more options. Choose the "Copy to clipboard" option from here.
Then you can drag your finger across the area of text you want selected. It will be highlighted on screen. Then click the tick icon in the top bar to finalise.
You can then swap app and paste the text out again. (All this assumes that the PDF has been built in a reasonable way so we can figure out what unicode char each glyph on the page corresponds to).
What MuPDF doesn't offer are the selection 'end tags' that you can drag with your finger. If you want that, you'll need to alter the android viewer specific java classes yourself. You shouldn't need to make any changes within the MuPDF core to support what you want. You might possibly need to tweak the JNI classes a bit.
It's probably not a huge job for a competent Android app developer, but it's too large for us to provide detailed information on a Stack Overflow answer.
If you have more questions, please don't hesitate to come visit us in the #ghostscript irc channel on freenode (see www.mupdf.com for a web link you can use if you don't have an irc client set up).
Upvotes: 6