Custom tools and menus with Android PDF Viewer SDK

Q: Hi, I’ve been using the mobile Android SDK and played with the sample apps and am very excited about it. However, I had a couple question about the accompanying Tools library. Is there any way to create your own custom tools that have access to the underlying text selection? I included two screen shots, the first is from your sample app and the second is from the stock browser. The stock browser uses the native selection handles while yours uses custom orange ones. Also the context menu seems to mimic iOS’s menus.

If want to create a custom tool do I instantiate the ToolsManager class? The documentation supplied with the SDK include the methods createDefaultTool and createTool but I don’t see any examples.

I attached a screenshot of the effect/style I would like to implement. Again, thank you for your time.

The Tools.jar library shipped with the SDK uses two interfaces: PDFViewCtrl.Tool and PDFViewCtrl.ToolManager to communicate with PDFViewCtrl. Licensed clients will have the source code of Tools.jar and hence be able to fully customize it. If you don’t have the source code yet, you cannot customize it. However, you can write your own tool library from scratch using the two interfaces mentioned above.

Q: I looked at the documentation for PDFViewCtrl.Tool and PDFViewCtrl.ToolManager but am still a little confused as to how to create a toolmanager. The sample code calls:


which takes an instantiated ToolManager from pdftron.PDF.Tools. What is the base class of ToolManager? Does it matter as long as it interfaces PDFViewCtrl.ToolManager?


The sample code has the following two lines:

pdftron.PDF.Tools.ToolManager tm = new pdftron.PDF.Tools.ToolManager();


So, you create a tool manager instance and associate it with PDFViewCtrl by calling setToolManager().

If you take a look at the online documentation at (please navigate to PDFViewCtrl.ToolManager), you will find the following:

Tool manager interface that is used for creating tools. PDFViewCtrl uses this interface, together with PDFViewCtrl.Tool interface, to interact with user-defined functional modules.

For example, in PDFViewCtrl’s PDFViewCtrl.onScroll(MotionEvent, MotionEvent, float, float) implementation, it has code similar to the following:

boolean handled = false;

int previous_tool_mode = mTool.getMode(), next_tool_mode;

do {

handled |= mTool.onMove(e1, e2, x_dist, y_dist);

next_tool_mode = mTool.getNextToolMode();

if (previous_tool_mode != next_tool_mode) {

mTool = mToolManager.createTool(next_tm, this, mTool);

previous_tool_mode = next_tool_mode;

} else {



} while (true);

if (handled) {



As shown above, Tool implementation decides what the next tool is. PDFViewCtrl uses PDFViewCtrl.Tool.getNextToolMode() to get the type of the next tool, uses createTool(int, pdftron.PDF.PDFViewCtrl, pdftron.PDF.PDFViewCtrl.Tool) to create the next tool, and calls the tool’s corresponding function, until the next tool is the same with the current tool. With this being said, a Tool implementation should prevent forming tools in a cyclic way. Note also that if the implementation’s PDFViewCtrl.Tool.onMove(MotionEvent, MotionEvent, float, float) returns true, the subsequent code of PDFViewCtrl.onScroll(MotionEvent, MotionEvent, float, float) won’t be executed, preventing the view from being scrolled.

Update: Starting with version 6.1.0 of the Android PDFNet SDK, the Tools library is now shipped as an Android Library, and its source code can be found in the samples folder. The package does not include the Tools.jar anymore, and you now have the flexibility to include the source directly into your project or create a separate library for your projects.