Custom Modals in WebViewer UI

WebViewer supports custom modals. There are multiple APIs to help you manage them.

To create a new custom modal, you can use the addCustomModal API. In order to create a custom modal, you need, at least, the dataElement that will be used to identify the modal, and the structural components header, body and footer.

The header element requires the following properties:

  • title String, required. Used for the title of the modal
  • className String, optional. CSS class name for the header section of the modal
  • style Object, optional. Inline style as an object, for example: { width: '12px', height: '23px', color: 'red' }
  • children Array, optional. The parameter for passing custom DOM elements to the header section of the modal

The body components is the main section of the custom modal and it requires following properties:

  • title String, optional. Used for the <p> text in body of the modal
  • className String, optional. CSS class name for the body section of the modal
  • style Object, optional. Inline style as an object, for example: { width: '12px', height: '23px', color: 'red' }
  • children Array, optional. The parameter for passing custom DOM elements to the body section of the modal

The footer section of the custom modal requires the following parameters:

  • className String, optional. CSS class name for the footer section of the modal
  • style Object, optional. Inline style as an object, for example: { width: '12px', height: '23px', color: 'red' }
  • children Array, optional. The parameter for passing custom DOM elements to the footer section of the modal

Once the custom modal is added, you can manage its visibility with these handy APIs:

Here is a code snippet that add a custom modal to WebViewer and immediately opens it:

JavaScript

1WebViewer({
2 initialDoc: "mydoc.pdf",
3 css: 'path/to/stylesheet.css'
4}, viewerElement).then(instance => {
5 // Creating HTML DOM elements
6 let divInput1 = document.createElement('input');
7 divInput1.type = 'text';
8 divInput1.id = 'unique_id_1';
9 divInput1.style = 'height: 28px; margin-top: 10px; margin-right: 20px';
10
11 let divInput2 = document.createElement('input');
12 divInput2.type = 'text';
13 divInput2.id = 'unique_id_2';
14 divInput2.style = 'height: 28px; margin-top: 10px;';
15
16 // Custom modal parameters
17 const modalOptions = {
18 dataElement: 'myCustomModal',
19 header: {
20 title: 'Header',
21 className: 'myCustomModal-header',
22 },
23 body: {
24 className: 'myCustomModal-body',
25 style: {},
26 children: [ divInput1, divInput2 ],
27 },
28 footer: {
29 className: 'myCustomModal-footer footer',
30 style: {},
31 children: [
32 {
33 title: 'Cancel',
34 button: true,
35 style: {},
36 className: 'modal-button cancel-form-field-button',
37 onClick: (e) => {console.log('Cancel button') }
38 },
39 {
40 title: 'OK',
41 button: true,
42 style: {},
43 className: 'modal-button confirm ok-btn',
44 onClick: (e) => { console.log('OK button') }
45 },
46 ]
47 }
48 }
49
50 instance.UI.addCustomModal(modalOptions);
51
52 instance.UI.openElements([modalOptions.dataElement]);
53});

For styling these components, see Customizing WebViewer UI Styles. Here is an example stylesheet file for the above code.

CSS

1.myCustomModal-header {
2 background-color: red;
3}
4
5.myCustomModal-body {
6 background-color: green;
7}
8
9.myCustomModal-footer {
10 background-color: blue;
11}

This is the output for the code above:

Apryse Docs Image

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales