Free Hand annotations are not persistent - Deleted when another tool is used

Product: PDFTron SDK

Product Version: 9.0177774


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:

  1. Free hand tool is selected and few lines are drawn. These are persistent until another tool is selected.
  2. Select another annotation tool and add few annoations. Now the lines added in step 1 is deleted
  3. 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)

Please let me know what could be the reason for this.

Thank You

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:


This fully depends on how you implemented the tool. Could you please provide a sample project so we can take a look?

Hi Shirley_Gong

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

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 =

    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.

  1. put a break point in FreehandCreate’s onClose to ensure that is called when you switch tool
  2. 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.

Hi Shirley_Gong

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.

Thank You

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)

Sep-02-2021 13-49-59

I was able to create the annotations without any issues by creating new instance everytime.

Thank you Shirley_Gong. :slight_smile: