There are two main types of headers. The first one is the top header. This header defaults to navigation tools, opening sub-menus and panels. Also in the center you will see a collection of toolbar group labels, called ribbons.
Selecting a toolbar group other than View will reveal the tools header. Each tools header has a different combination of tools. They can be modified individually.
Each header is represented by an array of header items. The array can be edited to add/remove/reorder items. The API, setHeaderItems, will provide the top header object as a function argument by default. To access a tools header please see the examples in the API link.
Customizing Ribbons
New in version 7.0, are the ribbons in the top header. This is a collection of toolbar groups. Each group reveals a second tools header that contain a different set of tools. There are various API calls that can be use to customize the ribbons.
To set a default to toolbar to load on startup, call setToolbarGroup. Alternatively, it can be called at any time to change the current toolbar group.
Lastly, you can move specific tools from one group to another. Below is an example of moving the line tool from the Shapes toolbar group to the Annotate toolbar group.
1// Moving the line tool from the 'Shapes' toolbar group to the 'Annotate' toolbar group
Header items are objects with certain properties. If you wish to add a header item, it is important for you to understand what type it is and what properties should be used.
ActionButton
ActionButton triggers an action. The button has no active state.
Properties
type (string) - Must be set to actionButton.
img (string) - Path to an image or base64 data. Can also be the filename of a .svg from the WebViewer
assets/icons/ folder (i.e. calibrate to use calibrate.svg).
onClick (function) - Function to be triggered on click.
title (string, optional) - Tooltip of the button.
dataElement (string, optional) - Option to set data-element value of the button element. It can be used to disable/enable the element.
hidden (array of strings, optional) - Option to hide the element at certain screen sizes. Accepted strings are desktop, tablet and mobile.
Example
JavaScript
1const newActionButton = {
2 type: 'actionButton',
3 img: 'path/to/image',
4 onClick: () => {
5 alert('Hello world!');
6 },
7 dataElement: 'alertButton',
8 hidden: [ 'mobile' ]
9};
StatefulButton
StatefulButton is a customizable button. You can decide how many states it has, what state is active and when to update the state.
Properties
type (string) - Must be set to statefulButton.
initialState (string) - String that is one of states object's keys.
states (object) - Object in the shape of: { nameOfState1: state1, nameOfState2: state2, ... }
Properties of a state:
img (string, optional): Path to an image or base64 data. Can also be the filename of a .svg from the WebViewer assets/icons/ folder (i.e. calibrate to use calibrate.svg).
getContent (function, optional): Function to be called when you update the state. Define this property if you don't use the img property for this button. Argument: activeState.
onClick (function): Function to be triggered on click. Arguments: update, activeState.
Any other properties you need.
mount (function) - Function to be called after the button is mounted into DOM
unmount (function, optional) - Function to be called before the button is unmounted from DOM.
dataElement (string, optional) - String to set data-element value of the button element. It can be used to disable/enable the element.
title (string, optional) - Tooltip of the button.
hidden (array of strings, optional) - Option to hide the element at certain screen sizes. Accepted strings are desktop, tablet and mobile.
Example
A stateful button that shows the count. And when you click it, it will increment the counter by 1.
JavaScript
1const countButton = {
2 type: 'statefulButton',
3 initialState: 'Count',
4 states: {
5 Count: {
6 number: 1,
7 getContent: activeState => {
8 return activeState.number;
9 },
10 onClick: (update, activeState) => {
11 activeState.number += 1;
12 update();
13 }
14 }
15 },
16 dataElement: 'countButton'
17};
A stateful button that shows the current page number. And when you click it, the document will go to next page. If you are already at the last page, the document will go to the first page.
1const nextPageButton = {
2 type: 'statefulButton',
3 initialState: 'Page',
4 states: {
5 Page: {
6 // Checkout https://docs.apryse.com/api/web/WebViewerInstance.html to see more APIs related with viewerInstance
ToggleElementButton opens/closes a UI element. The button is in an active state when the UI element is open.
Properties
type (string) - Must be set to toggleElementButton.
img (string) - Path to an image or base64 data. Can also be the filename of a .svg from the WebViewer assets/icons/ folder (i.e. calibrate to use calibrate.svg).
element (string) - data-element attribute value of the UI element to be opened/closed.
dataElement (string, optional) - Option to set data-element value of the button element. It can be used to disable/enable the element.
title (string, optional) - Tooltip of the button.
hidden (array of strings, optional) - Option to hide the element at certain screen sizes. Accepted strings are desktop, tablet and mobile.
Example
JavaScript
1const newToggleElementButton = {
2 type: 'toggleElementButton',
3 img: 'path/to/image',
4 element: 'leftPanel',
5 dataElement: 'leftPanelButton',
6 hidden: [ 'mobile' ]
7};
ToolButton
ToolButton activates a WebViewer tool. The button is in an active state when the tool is activated. To learn more about customizing annotation tools and tool buttons, see customizing tools.
Properties
type (string) - Must be set to toolButton.
toolName (string) - Name of the tool, which is either the key from toolModeMap or the name you registered your custom tool with. For custom tool registration, refer to registerTool.
title (string, optional) - Tooltip of the button.
hidden (array of strings, optional) - Option to hide the element at certain screen sizes. Accepted strings are desktop, tablet and mobile.
Example
JavaScript
1const newToolButton = {
2 type: 'toolButton',
3 toolName: 'AnnotationCreateFreeText',
4 hidden: [ 'mobile' ]
5}
ToolGroupButton
A ToolGroupButton shows the tools available to that tool group. Unless the img option is set, the button displays the image of one of the group members. The button is in an active state when any tool in the group is active. To learn more about customizing annotation tools and tool buttons, see customizing tools.
Properties
type (string) - Must be set to 'toolGroupButton'.
toolGroup (string) - Name of the tool group. In the default viewer, there are freeHandTools, textTools, shapeTools and miscTools.
img (string, optional) - Path to an image or base64 data. Can also be the filename of a .svg from the WebViewer assets/icons/ folder (i.e. calibrate to use calibrate.svg).
dataElement (string, optional) - Option to set data-element value of the button element. It can be used to disable/enable the element.
title (string, optional) - Tooltip of the button.
hidden (array of strings, optional) - Option to hide the element at certain screen sizes. Accepted strings are desktop, tablet and mobile.
Example
JavaScript
1const newToolGroupButton = {
2 type: 'toolGroupButton',
3 toolGroup: 'shapeTools',
4 dataElement: 'shapeToolGroupButton',
5 hidden: [ 'mobile' ]
6};
CustomElement
CustomElement takes a render function and renders DOM elements or React components. You may want to use this when the buttons above don't suffice.
Properties
type (string) - Must be set to 'customElement'.
title (string, optional) - Tooltip of the button.
render (func) - Function that returns DOM elements or React components
hidden (array of strings, optional) - Option to hide the element at certain screen sizes. Accepted strings are desktop, tablet and mobile.
Example
JavaScript
1const renderSlider = () => {
2 const slider = document.createElement('input');
3 slider.type = 'range';
4 slider.oninput = () => {
5 // Do something
6 };
7
8 return slider;
9}
10
11const newCustomElement = {
12 type: 'customElement',
13 render: renderSlider
14};
In React jsx:
JavaScript
1const Slider = () => {
2 return (
3 <input
4 type="range"
5 onInput={() => { /* Do something */ }}
6 >
7 </input>
8 );
9}
10
11const newCustomElement = {
12 type: 'customElement',
13 render: () => <Slider />
14};
Spacer
Spacer is just a div with flex: 1 to occupy any remaining space. It is used to push the buttons to each side on the default header.
Properties
type (string) - Must be set to 'spacer'.
hidden (array of strings, optional) - Option to hide the element at certain screen sizes. Accepted strings are desktop, tablet and mobile.
Example
JavaScript
1const newSpacer = {
2 type: 'spacer',
3 hidden: [ 'mobile' ]
4};
Divider
Divider renders a vertical bar with some margin to separate item groups.
Properties
type (string) - Must be set to 'divider'.
hidden (array of strings, optional) - Option to hide the element at certain screen sizes. Accepted strings are desktop, tablet and mobile.