-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.js
53 lines (48 loc) · 1.75 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
instance.UI.addEventListener(instance.UI.Events.VIEWER_LOADED, function() {
// instance.UI.disableElements(['printButton']);
// instance.UI.disableElements(['downloadButton']);
//add custom save button
const { documentViewer, annotationManager } = instance.Core;
instance.UI.setHeaderItems(header => {
header.push({
type: 'actionButton',
img: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path d="M17 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V7l-4-4zm-5 16c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm3-10H5V5h10v4z"/></svg>',
onClick: async () => {
const doc = documentViewer.getDocument();
const xfdfString = await annotationManager.exportAnnotations();
const data = await doc.getFileData({
// saves the document with annotations in it
xfdfString
});
const arr = new Uint8Array(data);
const blob = new Blob([arr], { type: 'application/pdf' });
let a = URL.createObjectURL(blob);
const payload = {
file: a
};
window.parent.postMessage({ type: 'SAVE_DOCUMENT', payload }, '*');
}
});
});
});
window.addEventListener("message", receiveMessage, false);
function receiveMessage(event) {
/**
* @note If you are using WebViewer version <= 7.x, please uncomment the line
* below
*/
// const instance = readerControl;
if (event.isTrusted && typeof event.data === 'object') {
switch (event.data.type) {
case 'OPEN_DOCUMENT':
instance.loadDocument(event.data.payload.file, {
officeOptions: {
disableBrowserFontSubstitution: true,
}
})
break;
default:
break;
}
}
}