In my project I am using PDFViewCtrl view and custom annoations to draw annotations. All the annotations are working fine except the Free Hand Ink tool. When the lines were drawn, they are getting deleted when another annotation tool is selected, ex: choosing stamp tool.
The scenario is:
Free hand tool is selected and few lines are drawn. These are persistent until another tool is selected.
Select another annotation tool and add few annoations. Now the lines added in step 1 is deleted
Now select free hand Ink tool again and add few lines. Now the lines added in step 1 are coming back.
The issue is not happening when using another tool like stamp, highlighter, text.
Below are the steps of screenshots 1, 2, 3 jpgs. (in 3rd screenshot the lines are back)
I can’t provide you the full project as it’s private to organisation. But here is the example code used to add Ink tool.
private fun usePenAnnotation() {
val toolPen = mToolManager?.createTool(
ToolManager.ToolMode.INK_CREATE,
mToolManager?.tool
) as FreehandCreate
tool.isForceSameNextToolMode = true
mToolManager?.tool = toolPen
}
And to toggle hightlighter, below code is used (or any other tool - all my tools are custom tool classes)
@Keep
class HighlighterAnnotation(ctrl: PDFViewCtrl) : FreeHighlighterCreate(ctrl) {
companion object {
var MODE = ToolManager.ToolMode.addNewMode(Annot.e_Highlight)
fun isForceNextSmartMode() = true
}
override fun getToolMode(): ToolManager.ToolModeBase {
return MODE
}
}
The below is invoked to select highligher
private fun useHighlighterAnnotation() {
// Highlighter
val toolHighlighterAnnotation = toolManager.createTool(HighlighterAnnotation.MODE, toolManager.tool)
(toolHighlighterAnnotation as Tool).isForceSameNextToolMode =
HighlighterAnnotation.isForceNextSmartMode()
mToolManager?.tool = toolHighlighterAnnotation
}
Please let me know if I am doing anything wrong here. After calling useHighlighterAnnotation() and drawing single highlighter line, the previous free hand pen line is gone.
Hi, since I cannot debug, you will need to do some debugging in your application.
put a break point in FreehandCreate’s onClose to ensure that is called when you switch tool
put a break point in commitInks to ensure that is called when you switch tool
If you still have difficulty, I would recommend create a minimum sample that can reproduce this so we can take a look. Switching tool is working correctly in all our samples. Thanks.
I have kept breakpoints at the locations as you suggested. Seems they are calling fine. I have created a sample project and could able to produce the issue.
You can find the project here
I have created a video of the output also. You can watch the behaviour here
Please let me know if I am doing anything wrong in the project. I have cloned the exact classes that I am using in another project.
Thanks for the project. The issue is you are creating all the tools at once, that’s actually not how our tools library is designed. Tools are supposed to be created on the go so it can have its own lifecycle, so upon start/finish of a tool, certain methods are called. There should only ever be 1 created tool at a time.
See updated source (I commented out everything but 2 tools to demonstrate): MainActivity.kt (6.9 KB)