Some test text!

menu
search
Annotation toolbarkeyboard_arrow_down

Annotation toolbar

AnnotationToolbar is a FrameLayout consisting of various annotation creation tools. With the annotation toolbar, users are able to conveniently create annotations and switch between different tools.

Annotation toolbar
To learn more about each icon, see the icon cheat sheet.
Screen SizeAnnotation Toolbar
Tablets or small devices in landscape modeMobile device in landscape mode + Tablet device
Small devices in portrait modeMobile device in portrait mode
Due to screen size limitations, only a limited number of tool icons will show up in portrait mode of smaller devices. This can be expanded by expanding the toolbar in the overflow menu.

linkShow and hide annotation toolbar

The annotation toolbar allows the user to easily switch tools when adding annotations to a document. To set up your layout with an annotation toolbar, add an <AnnotationToolbar> element to your XML layout. For example, your layout may look like this:

<com.pdftron.pdf.controls.AnnotationToolbar
    android:id="@+id/annotationToolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="@dimen/actionbar_elevation"/>

Then in your activity, you attach a ToolManager to the annotation toolbar:

private ToolManager mToolManager;
private AnnotationToolbar mAnnotationToolbar;
// ...
public void setupAnnotationToolbar() {
    mAnnotationToolbar = findViewById(R.id.annotationToolbar);
    // Remember to initialize your ToolManager before calling setup
    mAnnotationToolbar.setup(mToolManager);
    mAnnotationToolbar.show();
}

To close the annotation toolbar programmatically call:

mAnnotationToolbar.close();

To handle device rotation, call AnnotationToolbar.onConfigurationChanged(Configuration) in your activity:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    mAnnotationToolbar.onConfigurationChanged(newConfig);
}

linkStart mode

There are 3 start modes to choose from when showing the toolbar using show(int) API:

  • normal mode: showing all types of annotation creation tools
  • edit mode: showing one type of advanced annotation creation mode (i.e. cloud)
  • form mode: showing all types of form widget creation tools

linkHide annotation toolbar items

By default, all enabled annotation type icons will show up on the following situations:

  • all orientations on tablet
  • portrait orientation on phone with expanded mode
  • landscape orientation on phone

It is possible to choose which icons show up in portrait orientation on phone when collapsed, as well as hide any of the icons in the toolbar in all situations. The following section will go through each scenario.

linkPrecedence when space is limited

In portrait orientation on phone when collapsed, the following icons will show up by default:

  • Sticky note icon group
  • Text highlight
  • Text underline
  • Signature
  • Ink
  • Free text group

This can be customized as follows:

ToolManagerBuilder tmBuilder = ToolManagerBuilder.from()
    // shows free text, ink, square, and line
    .setAnnotToolbarPrecedence(new ToolManager.ToolMode[] {
        ToolManager.ToolMode.TEXT_CREATE,
        ToolManager.ToolMode.INK_CREATE,
        ToolManager.ToolMode.RECT_CREATE,
        ToolManager.ToolMode.LINE_CREATE
    });

// Or using ToolManager
// shows free text, ink, square, and line
mToolManager.setAnnotToolbarPrecedence(new ToolManager.ToolMode[] {
    ToolManager.ToolMode.TEXT_CREATE,
    ToolManager.ToolMode.INK_CREATE,
    ToolManager.ToolMode.RECT_CREATE,
    ToolManager.ToolMode.LINE_CREATE
});

linkHide tool buttons

If there are tools that you would like to remove from the annotation toolbar, you can disable them by calling ToolManager.disableToolMode(ToolMode[]). This will also hide the tool in the quick menu. For example:

// Disable TextHighlightCreate tool, TextUnderlineCreate tool,
// TextSquigglyCreate tool and TextStrikeoutCreate tool
mToolManager.disableToolMode(new ToolMode[]{
    ToolManager.ToolMode.TEXT_HIGHLIGHT,
    ToolManager.ToolMode.TEXT_UNDERLINE,
    ToolManager.ToolMode.TEXT_SQUIGGLY,
    ToolManager.ToolMode.TEXT_STRIKEOUT}
);

Then, when you open the annotation toolbar you will see:

In portrait mode: annotation toolbar image

In landscape mode: annotation toolbar image

For reference, a mapping of ToolMode to button icons is shown below:

IconToolMode
Rectangle imageRECT_CREATE
Ellipse imageOVAL_CREATE
Polyline imagePOLYLINE_CREATE
Polygon imagePOLYGON_CREATE
Cloud imageCLOUD_CREATE
Line imageLINE_CREATE
Arrow imageARROW_CREATE
Ruler imageRULER_CREATE
Free text imageTEXT_CREATE
Callout imageCALLOUT_CREATE
Note imageTEXT_ANNOT_CREATE
Ink imageINK_CREATE
Eraser imageINK_ERASER
Signature imageSIGNATURE
Stamp imageSTAMPER
Rubber stamp imageRUBBER_STAMPER
Free highlighter imageFREE_HIGHLIGHTER
Highlight imageTEXT_HIGHLIGHT
Underline imageTEXT_UNDERLINE
Squiggly imageTEXT_SQUIGGLY
Strikeout imageTEXT_STRIKEOUT
Sound imageSOUND_CREATE
File attachment imageFILE_ATTACHMENT_CREATE
Text field imageFORM_TEXT_FIELD_CREATE
Checkbox field imageFORM_CHECKBOX_CREATE
Group select imageANNOT_EDIT_RECT_GROUP

linkHide other buttons

If you would like to hide other buttons in the annotation toolbar that are not tied to any specific tool (e.g. Pan, Close, and Overflow buttons), you can do so by calling AnnotationToolbar.hideButton with a ToolbarButtonId from the table below:

IconToolbar Button Id
Pan imagePAN
Close imageCLOSE
Overflow imageOVERFLOW

linkRemove default tool grouping

By default, annotation creation tools are grouped in four categories:

  • Open shape group: line, arrow, polyline, ruler
  • Closed shape group: rectangle, ellipse, polygon, cloud
  • FreeText group: free text, callout
  • Icon group: sticky note, sound

It is possible to change the default grouping, for example, to remove the last icon group:

int size = mAnnotationToolbar.getGroupItems().size();
mAnnotationToolbar.getGroupItems().remove(size - 1);

linkUndo/redo

If undo/redo is enabled in the PDFViewCtrl then the buttons for undo/redo will be provided as a popup window when the user clicks on the three vertical dots at the right end of the toolbar.

linkListeners

linkAnnotation toolbar listener

You can set an AnnotationToolbarListener to be notified of annotation toolbar events (such as the toolbar being shown or closed) by calling setAnnotationToolbarListener.

Example

mAnnotationToolbar.setAnnotationToolbarListener(new AnnotationToolbar.AnnotationToolbarListener() {
    @Override
    public void onShowAnnotationToolbarByShortcut(final int mode) {
        // If you would like to support keyboard shortcuts, show the annotation  
        // toolbar here, or hide the toolbar if the document is read-only
    }

    @Override
    public void onAnnotationToolbarShown() {
        // Called when toolbar is shown
    }

    @Override
    public void onAnnotationToolbarClosed() {
        // Called when toolbar is closed
    }
});

In addition, the onShowAnnotationToolbarByShortcut(int) method is invoked when the user presses a shortcut that brings up the annotation toolbar. You should implement this method to start the annotation toolbar with a specific tool mode selected or to keep the annotation toolbar hidden if the document has read-only access.

linkUndo/Redo listener

To be notified when the undo/redo buttons are clicked, you should set an OnUndoRedoListener by calling setOnUndoRedoListener.

Example

mAnnotationToolbar.setOnUndoRedoListener(new UndoRedoPopupWindow.OnUndoRedoListener() {
    @Override
    public void onUndoRedoCalled() {
        // Refresh the current page number and the total number of pages if they are shown over the viewer
    }
});

linkEdit annotations continuously

By default, the annotation toolbar returns to the pan tool after an annotation is created. If you prefer to keep the same tool mode after an annotation is created you should call:

mAnnotationToolbar.setButtonStayDown(true);

linkAppearance styles

In order to customize the appearance of UI elements in your annotation toolbar, you can define an annotation_toolbar style inside your res\values\style.xml file:

<style name="YourAppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
    <item name="colorPrimary">@color/app_color_primary_day</item>
    <item name="colorPrimaryDark">@color/app_color_primary_dark_day</item>
    <item name="colorAccent">@color/app_color_accent</item>

    <item name="annotation_toolbar">@style/CustomAnnotationToolbarStyle</item>
    <item name="edit_toolbar">@style/CustomEditToolbarStyle</item>
    <item name="form_toolbar">@style/CustomFormToolbarStyle</item>
</style>

<style name="CustomAnnotationToolbarStyle" parent="AnnotationToolbarStyle">
    <item name="colorBackground">@android:color/black</item>
</style>

<style name="CustomEditToolbarStyle" parent="EditToolbarStyle">
    <item name="colorBackground">@android:color/black</item>
</style>

<style name="CustomFormToolbarStyle" parent="FormToolbarStyle">
    <item name="colorBackground">@android:color/black</item>
</style>

Alternatively, you can change the attributes inside your xml layout:

<com.pdftron.pdf.controls.AnnotationToolbar
  android:id="@+id/annotationToolbar"
  app:colorBackground="@android:color/black"
    ... 
/>

linkXML attributes

AttributeDescriptionFormat
app:colorBackgroundSpecifies the annotation toolbar background color.

Default value: ?attr/colorPrimary
Color
app:colorToolBackgroundSpecifies the background color of each tool in annotation toolbar.

Default value: ?attr/colorPrimaryDark
Color
app:colorToolIconSpecifies the icon color of each tool (except the close button) in annotation toolbar.

Default value: @android:color/white
Color
app:colorCloseIconSpecifies the icon color of the close button in annotation toolbar.

Default value: @android:color/white
Color

Get the answers you need: Support

close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

PDFTron Receives USD$71 Million Growth Investment Led By Silversmith Capital Partners

Learn More
close