1const viewerElement = document.getElementById("viewer");
2
3const openFileBtn = document.getElementById("open");
4const saveFileBtn = document.getElementById("save");
5
6WebViewer(
7 {
8 path: "../lib/webviewer",
9 initialDoc: "https://apryse.s3.amazonaws.com/public/files/samples/WebviewerDemoDoc.pdf",
10 },
11 viewerElement
12).then((instance) => {
13 // Interact with APIs here.
14 instance.UI.setTheme('dark');
15 instance.UI.disableElements(['downloadButton']);
16
17 const { documentViewer, annotationManager } = instance.Core;
18
19 openFileBtn.onclick = async () => {
20 const filePath = await window.electronAPI.openFile();
21 if (!filePath) {
22 return;
23 }
24 instance.UI.loadDocument(filePath);
25 };
26
27 saveFileBtn.onclick = async () => {
28 const doc = documentViewer.getDocument();
29 const xfdfString = await annotationManager.exportAnnotations();
30 const data = await doc.getFileData({
31 // saves the document with annotations in it
32 xfdfString,
33 });
34 const arr = new Uint8Array(data);
35
36 window.electronAPI.saveFile(arr);
37 };
38});
39