UI Import and Export

With the WebViewer Modular UI, it is possible to import and export an entire UI configuration using JSON.

This provides a simple and efficient way to customize the Webviewer UI whether starting from the out of the box UI or assembling something new using modular components. A configuration can be saved as a separate file or worked on as an object to make customization and editing easier with all the different components available in one place.

A configuration can contain:

Import a Modular UI

To use a Modular UI configuration, it needs to be imported into WebViewer. The configuration can be imported using the UI.importModularComponents method. The method takes a configuration JSON object as a parameter along with an optional function map.

JavaScript

1instance.UI.importModularComponents(configUI);

The import method will validate the configuration to ensure that it is correctly formatted and that all Modular Components, Modular Headers, Flyouts, and Panels have their necessary properties. If any errors are found, an error message will be printed in the console and the import operation will be aborted.

Apryse Docs Image

In the example above, there is an error thrown which shows that a component menu-toggle-button has an invalid key type and explains which type properties are valid.

Adding a Function Map

Functions cannot be imported and exported via JSON but a function map can be used to define functions like onClick on components such as Custom Buttons. The function map is kept separately from the Modular UI configuration. It needs to contain all functions that are used by custom components as they cannot be exported along with the other components in a JSON format.

The function map should contain one object with keys to denote the name of the function and the value as the function itself. As shown below:

JavaScript

1const functionMap = {
2 'alertClick': () => alert('Alert triggered!'),
3 'flyoutSecondButtonOnClick': () => {
4 console.log('Second Item clicked!');
5 },
6};

You can then refer to functions in the function map by their key in your modularComponents. For example, the alertClick function key can be added to a Custom Button as shown below:

JavaScript

1{
2 "modularComponents": {
3 "myButton": {
4 "type": "customButton",
5 "dataElement": "myButton",
6 "label": "My Button",
7 "onClick": "alertClick"
8 },
9 "flyoutFirstButton": {
10 "type": "customButton",
11 "dataElement": "flyoutFirstButton",
12 "label": "Flyout First Button",
13 "children": ["flyoutSecondButton"]
14 },
15 "flyoutSecondButton": {
16 "type": "customButton",
17 "dataElement": "flyoutSecondButton",
18 "label": "Flyout Second Button",
19 "onClick": "flyoutSecondButtonOnClick"
20 }
21 }
22}

The function map can be added by importing it along with the UI configuration.

JavaScript

1instance.UI.importModularComponents(configUI, functionMap);

Importing with a Function Map

The function map should always be reimported along with its associated configuration.

Export a Modular UI

A Modular UI configuration can be exported from WebViewer using the UI.exportModularComponents method. The method will return a JSON object containing all the Modular Components, Headers, Flyouts, and Panels that have been added to the UI.

JavaScript

1instance.UI.exportModularComponents();

Exporting Functions

Since functions can't be stored in JSON, only the function key will be exported. Read more about creating and maintaining your function map here.

When exporting a Modular UI configuration, a JSON object will be returned. The JSON object can then be copied or saved to a file for viewing and editing.

Components are validated upon export and must include a data element to be exported successfully. Any validation warnings will be printed to the console.

If there are any functions that are referred to by components in the Modular UI and they are not included in a function map, they will be printed in a console warning.

Apryse Docs Image

The function can then be copied and added to the function map when importing the configuration.

Modular UI Configuration Structure

A Modular UI configuration is a JSON object that contains all the components that are used to build a UI. The configuration can contain the following properties:

Apryse Docs Image

The above properties can be reordered in any way that is convenient for the user. Each property can contain multiple objects with each object representing a component that is used in the UI.

To define each component and its properties within the top-level objects of the configuration structure, they should be given an object key which should also be the dataElement of the component. The dataElement is a unique identifier used to refer to the component in the UI.

JavaScript

1{
2 "modularComponents": {
3 "myButton": {
4 dataElement: "myButton",
5 }
6 }
7}

Modular Components

Modular Components can be added to a UI configuration by adding a modularComponents property with all components as child objects. Modular Components refer to any items or containers that can be added to a Modular Header or a Flyout. A valid Modular Component in the configuration needs to include a dataElement property (or object key) that is unique to the component.

Modular components also need to contain a type property so that WebViewer knows which kind of component it needs to create. The type property can be any of the item types normally added to a Modular Header or Flyout. More detail in the list of item types - api definitions.

To add components to the UI, their object keys (dataElement) need to be included in the items property of a Modular Header or Flyout. Since Flyouts support a nested structure, items can also be included in the children property to create a nested Flyout.

Modular Components should be added to the configuration as shown below. In this example, a Button component is added to the configuration with a dataElement of myButton and a label of My Button. It also calls an onClick function of alertClick when clicked. The logic for alertClick is stored in the function map and only referenced in the configuration JSON.

JavaScript

1{
2 "modularComponents": {
3 "myButton": {
4 "type": "customButton",
5 "dataElement": "myButton",
6 "label": "My Button",
7 "onClick": "alertClick"
8 }
9 }
10}

For more information on items which can be used in Modular Components, refer to the Items and Containers documentation.

Modular Headers

Modular Headers can be easily created by adding a modularHeaders property with each header listed as a child object to your UI configuration.

Each header can have an items property which should contain an array of dataElements of the components to be added to the header. The items contained in a header all need to be valid and included in the modularComponents section of the modular UI configuration in order to be used.

There also needs to be a placement property that specifies where the header should be placed in the UI. The placement property can be any of the following values: top, left, right, or bottom.

Modular headers can also include any of the container properties used to customize how they appear in your UI.

Modular Headers should be added to the configuration as shown below. In this example, a Modular Header is added to the configuration JSON with a dataElement of myHeader and a placement of top. The items property contains an array with the dataElement of the Button component that was added earlier.

JavaScript

1{
2 "modularHeaders": {
3 "myHeader": {
4 "dataElement": "myHeader",
5 "placement": "top",
6 "items": ["flyoutToggle", "myButton", "searchPanelToggle"]
7 }
8 }
9}

For more information on Modular Headers, refer to the Modular Headers documentation.

Flyouts

Flyouts are menus which are toggled by a component (ie. a Toggle Element Button) and can be added to the JSON by adding a flyouts property.

Flyouts can contain items similarly to headers but in the case of a Flyout, the items can also be used to create submenus when they have a children property which contains other items. The items property should contain an array of dataElements of the components to be added to the first level of the Flyout.

The example below shows how to create a simple Modular UI configuration which includes a header that contains a Toggle Element Button to open a Flyout. The Flyout contains a Custom Button which has a children property that contains another Custom Button which is opened as a submenu.

Apryse Docs Image

JavaScript

1{
2 "modularComponents": {
3 "flyoutToggle": {
4 "type": "toggleButton",
5 "img": "ic-hamburger-menu",
6 "dataElement": "flyoutToggle",
7 "toggleElement": "myFlyout"
8 },
9 "flyoutFirstButton": {
10 "type": "customButton",
11 "dataElement": "flyoutFirstButton",
12 "label": "Flyout First Button",
13 "children": ["flyoutSecondButton"]
14 },
15 "flyoutSecondButton": {
16 "type": "customButton",
17 "dataElement": "flyoutSecondButton",
18 "label": "Flyout Second Button",
19 "onClick": "flyoutSecondButtonOnClick"
20 },
21 },
22 "modularHeaders": {
23 "myHeader": {
24 "dataElement": "myHeader",
25 "placement": "top",
26 "items": ["flyoutToggle"]
27 }
28 },
29 "flyouts": {
30 "myFlyout": {
31 "dataElement": "myFlyout",
32 "items": ["flyoutFirstButton"]
33 }
34 }
35}

Default Navigation

Chevrons to denote that an item has children are added automatically. Back buttons are also added automatically to help with Flyout navigation.

Panels

Panels can be included by adding a panels property with each panel listed as a child object in the configuration.

Panels need to include a location property that specifies where the panel should be placed in the UI. The location property can be either left or right.

They must also include a render property that specifies which Panel to render. The render property can include a prebuilt panel name or it can be tabPanel which allows you to create a Tabbed Panel.

Custom Panels

Currently, Custom Panels cannot be imported and exported, but they can still be added to a UI using the addPanel API

The following example shows how to add a panel that is rendered as a Search Panel to a Modular UI configuration.

JavaScript

1{
2 "panels": {
3 "myPanel": {
4 "dataElement": "myPanel",
5 "location": "left",
6 "render": "searchPanel"
7 }
8 }
9}

The next example shows how to create a Modular UI configuration that includes a Tabbed Panel similar to the one in the Default UI.

Apryse Docs Image

JavaScript

1Webviewer.WebComponent(
2 {
3 path: '/path/to/your/webviewer',
4 initialDoc: '/path/to/your/document.pdf',
5 ui: 'beta' // enable Modular UI
6 },
7 viewerElement
8).then((instance) => {
9 const configUI = {
10 "modularComponents": {
11 "left-panel-toggle": {
12 "dataElement": "left-panel-toggle",
13 "title": "Left Panel",
14 "type": "toggleButton",
15 "img": "icon-header-sidebar-line",
16 "toggleElement": "customLeftPanel"
17 }
18 },
19 "modularHeaders": {
20 "default-top-header": {
21 "dataElement": "default-top-header",
22 "placement": "top",
23 "items": [
24 "left-panel-toggle"
25 ]
26 }
27 },
28 "panels": {
29 "customLeftPanel": {
30 "render": "tabPanel",
31 "dataElement": "customLeftPanel",
32 "panelsList": [
33 {
34 "render": "thumbnailPanel"
35 },
36 {
37 "render": "outlinesPanel"
38 },
39 {
40 "render": "bookmarkPanel"
41 },
42 {
43 "render": "layersPanel"
44 },
45 {
46 "render": "signaturePanel"
47 },
48 {
49 "render": "fileAttachmentPanel"
50 },
51 {
52 "render": "portfolioPanel"
53 }
54 ],
55 "location": "left"
56 },
57 "thumbnailPanel": {
58 "dataElement": "thumbnailPanel",
59 "render": "thumbnailsPanel",
60 "location": "left"
61 },
62 "outlinesPanel": {
63 "dataElement": "outlinesPanel",
64 "render": "outlinesPanel",
65 "location": "left"
66 },
67 "bookmarkPanel": {
68 "dataElement": "bookmarkPanel",
69 "render": "bookmarksPanel",
70 "location": "left"
71 },
72 "layersPanel": {
73 "dataElement": "layersPanel",
74 "render": "layersPanel",
75 "location": "left"
76 },
77 "fileAttachmentPanel": {
78 "dataElement": "fileAttachmentPanel",
79 "render": "fileAttachmentPanel",
80 "location": "left"
81 },
82 "signaturePanel": {
83 "dataElement": "signaturePanel",
84 "render": "signaturePanel",
85 "location": "left"
86 },
87 "portfolioPanel": {
88 "dataElement": "portfolioPanel",
89 "render": "portfolioPanel",
90 "location": "left"
91 }
92 }
93 };
94
95 instance.UI.importModularComponents(configUI);
96});

Examples

Basic Modular UI Example

The following example shows how to create a basic Modular UI configuration. It includes a Custom Button, a Custom Header, a Panel, and a Flyout with a submenu. The configuration JSON object is then imported into WebViewer along with a function map that contains functions for the Custom Buttons.

JavaScript

1WebViewer(
2 {
3 path: '/path/to/your/webviewer',
4 initialDoc: '/path/to/your/document.pdf',
5 },
6 // your viewer element
7 document.getElementById('viewer')
8).then((instance) => {
9 const configUI = {
10 "modularComponents": {
11 "myButton": {
12 "type": "customButton",
13 "dataElement": "myButton",
14 "label": "My Button",
15 "onClick": "alertClick"
16 },
17 "flyoutToggle": {
18 "type": "toggleButton",
19 "img": "ic-hamburger-menu",
20 "dataElement": "flyoutToggle",
21 "toggleElement": "myFlyout"
22 },
23 "flyoutFirstButton": {
24 "type": "customButton",
25 "dataElement": "flyoutFirstButton",
26 "label": "Flyout First Button",
27 "children": [
28 "flyoutSecondButton"
29 ]
30 },
31 "flyoutSecondButton": {
32 "type": "customButton",
33 "dataElement": "flyoutSecondButton",
34 "label": "Flyout Second Button",
35 "onClick": "flyoutSecondButtonOnClick"
36 },
37 "searchPanelToggle": {
38 "type": "toggleButton",
39 "img": "icon-header-search",
40 "dataElement": "searchPanelToggle",
41 "toggleElement": "myPanel"
42 }
43 },
44 "modularHeaders": {
45 "myHeader": {
46 "dataElement": "myHeader",
47 "placement": "top",
48 "items": [
49 "flyoutToggle",
50 "myButton",
51 "searchPanelToggle"
52 ]
53 }
54 },
55 "panels": {
56 "myPanel": {
57 "dataElement": "myPanel",
58 "location": "left",
59 "render": "searchPanel"
60 }
61 },
62 "flyouts": {
63 "myFlyout": {
64 "dataElement": "myFlyout",
65 "items": [
66 "flyoutFirstButton"
67 ]
68 }
69 }
70 };
71
72 const functionMap = {
73 'alertClick': () => alert('Alert triggered!'),
74 'flyoutSecondButtonOnClick': () => {
75 console.log('Second Item clicked!');
76 },
77 };
78
79 instance.UI.importModularComponents(configUI, functionMap);
80});

Working with the Default UI

The following example was build using an export of the Default UI as a base.

It has been customized by editing the default ribbon to only contain the View and Annotate ribbon items, and adding the page navigation buttons to the top header.

It also has some reordered tools in the Annotate ribbon group which will now open on the left side of the UI instead of at the top underneath the default header. The Style Panel’s location has changed to open on the right instead of the left as well.

Finally, the main menu flyout was also customized to include only the Open File and Save As buttons.

There is no need to include a function map in this example as no custom functions are used in the configuration.

See the comments in the code snippet below to understand how the configuration was built.

JavaScript

1WebViewer(
2 {
3 path: '/path/to/your/webviewer',
4 initialDoc: '/path/to/your/document.pdf',
5 // add Open File button to the Main Menu
6 enableFilePicker: true,
7 },
8 // your viewer element
9 document.getElementById('viewer')
10).then((instance) => {
11 const configUI = {
12 "modularComponents": {
13 // only include the buttons, grouped items, dividers,
14 // ribbon items, and ribbon groups that are needed here
15 "page-controls-container": {
16 "dataElement": "page-controls-container",
17 "type": "pageControls"
18 },
19 "filePickerButton": {
20 "dataElement": "filePickerButton",
21 "type": "presetButton"
22 },
23 "saveAsButton": {
24 "dataElement": "saveAsButton",
25 "type": "presetButton"
26 },
27 "menu-toggle-button": {
28 "dataElement": "menu-toggle-button",
29 "img": "ic-hamburger-menu",
30 "title": "component.menuOverlay",
31 "toggleElement": "MainMenuFlyout",
32 "type": "toggleButton"
33 },
34 "zoom-container": {
35 "dataElement": "zoom-container",
36 "type": "zoom"
37 },
38 "highlightToolButton": {
39 "dataElement": "highlightToolButton",
40 "type": "toolButton",
41 "toolName": "AnnotationCreateTextHighlight"
42 },
43 "underlineToolButton": {
44 "dataElement": "underlineToolButton",
45 "type": "toolButton",
46 "toolName": "AnnotationCreateTextUnderline"
47 },
48 "strikeoutToolButton": {
49 "dataElement": "strikeoutToolButton",
50 "type": "toolButton",
51 "toolName": "AnnotationCreateTextStrikeout"
52 },
53 "squigglyToolButton": {
54 "dataElement": "squigglyToolButton",
55 "type": "toolButton",
56 "toolName": "AnnotationCreateTextSquiggly"
57 },
58 "freeTextToolButton": {
59 "dataElement": "freeTextToolButton",
60 "type": "toolButton",
61 "toolName": "AnnotationCreateFreeText"
62 },
63 "rectangleToolButton": {
64 "dataElement": "rectangleToolButton",
65 "type": "toolButton",
66 "toolName": "AnnotationCreateRectangle"
67 },
68 "markInsertTextToolButton": {
69 "dataElement": "markInsertTextToolButton",
70 "type": "toolButton",
71 "toolName": "AnnotationCreateMarkInsertText"
72 },
73 "markReplaceTextToolButton": {
74 "dataElement": "markReplaceTextToolButton",
75 "type": "toolButton",
76 "toolName": "AnnotationCreateMarkReplaceText"
77 },
78 "freeHandToolButton": {
79 "dataElement": "freeHandToolButton",
80 "type": "toolButton",
81 "toolName": "AnnotationCreateFreeHand"
82 },
83 "freeHandHighlightToolButton": {
84 "dataElement": "freeHandHighlightToolButton",
85 "type": "toolButton",
86 "toolName": "AnnotationCreateFreeHandHighlight"
87 },
88 "stickyToolButton": {
89 "dataElement": "stickyToolButton",
90 "type": "toolButton",
91 "toolName": "AnnotationCreateSticky"
92 },
93 "divider-0.4011225832731946": {
94 "dataElement": "divider-0.4011225832731946",
95 "type": "divider"
96 },
97 "stylePanelToggle": {
98 "dataElement": "stylePanelToggle",
99 "title": "action.style",
100 "type": "toggleButton",
101 "img": "icon-style-panel-toggle",
102 "toggleElement": "stylePanel"
103 },
104 "divider-0.5730925860609144": {
105 "dataElement": "divider-0.5730925860609144",
106 "type": "divider"
107 },
108 "undoButton": {
109 "dataElement": "undoButton",
110 "type": "presetButton",
111 "buttonType": "undoButton"
112 },
113 "redoButton": {
114 "dataElement": "redoButton",
115 "type": "presetButton",
116 "buttonType": "redoButton"
117 },
118 "eraserToolButton": {
119 "dataElement": "eraserToolButton",
120 "type": "toolButton",
121 "toolName": "AnnotationEraserTool"
122 },
123 "defaultAnnotationUtilities": {
124 "dataElement": "defaultAnnotationUtilities",
125 // items here are defined above
126 "items": [
127 "divider-0.4011225832731946",
128 "stylePanelToggle",
129 "divider-0.5730925860609144",
130 "undoButton",
131 "redoButton",
132 "eraserToolButton"
133 ],
134 "type": "groupedItems",
135 "grow": 0,
136 "gap": 12,
137 "alwaysVisible": false,
138 "style": {}
139 },
140 "annotateGroupedItems": {
141 "dataElement": "annotateGroupedItems",
142 // items here are defined above
143 "items": [
144 "underlineToolButton",
145 "highlightToolButton",
146 "rectangleToolButton",
147 "freeTextToolButton",
148 "freeHandToolButton",
149 "freeHandHighlightToolButton",
150 "stickyToolButton",
151 "squigglyToolButton",
152 "strikeoutToolButton",
153 "markInsertTextToolButton",
154 "markReplaceTextToolButton",
155 "defaultAnnotationUtilities"
156 ],
157 "type": "groupedItems",
158 "justifyContent": "center",
159 "grow": 0,
160 "gap": 12,
161 "alwaysVisible": false,
162 "style": {}
163 },
164 "toolbarGroup-View": {
165 "dataElement": "toolbarGroup-View",
166 "title": "View",
167 "type": "ribbonItem",
168 "label": "View",
169 "groupedItems": [],
170 "toolbarGroup": "toolbarGroup-View"
171 },
172 "toolbarGroup-Annotate": {
173 "dataElement": "toolbarGroup-Annotate",
174 "title": "Annotate",
175 "type": "ribbonItem",
176 "label": "Annotate",
177 "groupedItems": [
178 "annotateGroupedItems"
179 ],
180 "toolbarGroup": "toolbarGroup-Annotate"
181 },
182 "default-ribbon-group": {
183 "dataElement": "default-ribbon-group",
184 // include all the tool groups that you want in the ribbon here
185 "items": [
186 "toolbarGroup-View",
187 "toolbarGroup-Annotate"
188 ],
189 "type": "ribbonGroup",
190 "justifyContent": "center",
191 "grow": 2,
192 "gap": 12,
193 "alwaysVisible": false,
194 "style": {}
195 },
196 "searchPanelToggle": {
197 "dataElement": "searchPanelToggle",
198 "title": "component.searchPanel",
199 "type": "toggleButton",
200 "img": "icon-header-search",
201 "toggleElement": "searchPanel"
202 },
203 "notesPanelToggle": {
204 "dataElement": "notesPanelToggle",
205 "title": "component.notesPanel",
206 "type": "toggleButton",
207 "img": "icon-header-chat-line",
208 "toggleElement": "notesPanel"
209 }
210 },
211 "modularHeaders": {
212 "default-top-header": {
213 "dataElement": "default-top-header",
214 "placement": "top",
215 "grow": 0,
216 "gap": 12,
217 "position": "start",
218 "float": false,
219 "stroke": true,
220 "dimension": {
221 "paddingTop": 8,
222 "paddingBottom": 8,
223 "borderWidth": 1
224 },
225 "style": {},
226 // include all items that you want in the top header here
227 "items": [
228 "menu-toggle-button",
229 "zoom-container",
230 "default-ribbon-group",
231 "searchPanelToggle",
232 "notesPanelToggle",
233 "page-controls-container"
234 ]
235 },
236 "tools-header": {
237 "dataElement": "tools-header",
238 // choose where you want to place the secondary header here
239 "placement": "left",
240 "justifyContent": "start",
241 "grow": 0,
242 "gap": 12,
243 "position": "end",
244 "float": false,
245 "stroke": true,
246 "dimension": {
247 "paddingTop": 8,
248 "paddingBottom": 8,
249 "borderWidth": 1
250 },
251 "style": {},
252 "items": [
253 "annotateGroupedItems"
254 ]
255 }
256 },
257 "panels": {
258 // placing all the panels on the right side
259 // since the left side is already occupied by the tools header
260 "stylePanel": {
261 "dataElement": "stylePanel",
262 "render": "stylePanel",
263 "location": "right"
264 },
265 "notesPanel": {
266 "dataElement": "notesPanel",
267 "render": "notesPanel",
268 "location": "right"
269 },
270 "searchPanel": {
271 "dataElement": "searchPanel",
272 "render": "searchPanel",
273 "location": "right"
274 }
275 },
276 "flyouts": {
277 "MainMenuFlyout": {
278 "dataElement": "MainMenuFlyout",
279 "items": [
280 // include the buttons that are needed in the Main Menu here
281 "filePickerButton",
282 "divider",
283 "saveAsButton"
284 ]
285 }
286 }
287 };
288
289 instance.UI.importModularComponents(configUI);
290});

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales