Interacting with tools with the Document Viewer

DocumentViewer comes with ability to change and use tools within the viewer element. Tools are used to create/interact with annotations, select text, and perform other actions. They are found in the Core.Tools namespace. Not only are tools used in the default WebViewer setup, they can also be used in your custom viewer.

Getting tools

Although you can instantiate a tool manually, this is typically not necessary as the DocumentViewer comes with some default, initialized tools. You can get one of the tools using the getTool API and the name that the tool was registered with.

JavaScript

1const editTool = documentViewer.getTool('AnnotationEdit');

There is an enumeration, Core.Tools.ToolNames, that makes this accessing the tools easier.

JavaScript

1const editTool = documentViewer.getTool(Core.Tools.ToolNames.EDIT);

When there is an active tool, you can fetch it directly using the getToolMode API.

JavaScript

1const currentTool = documentViewer.getToolMode();

Changing tools

You can call the setToolMode API to change tools from the DocumentViewer.

JavaScript

1documentViewer.addEventListener('documentLoaded', () => {
2 // Changes to the edit tool on every document load
3 documentViewer.setToolMode(documentViewer.getTool(Core.Tools.ToolNames.EDIT));
4});

Next steps

Learn more about annotations and the tools that create them!

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales