1WebViewer({
2 fullAPI: true,
3 disableMultiViewerComparison: true, // Disable default compare buttons
4}, document.getElementById('viewer'))
5.then((instance) => {
6 const { UI, Core } = instance;
7 const { Annotations } = Core;
8 const { Color } = Annotations;
9
10 UI.addEventListener(UI.Events.MULTI_VIEWER_READY, () => {
11 const [documentViewer1, documentViewer2] = Core.getDocumentViewers();
12 const startCompare = async () => {
13 const shouldCompare = documentViewer1.getDocument() && documentViewer2.getDocument();
14 if (shouldCompare) { // Check if both documents loaded before comparing
15 const beforeColor = new Color(21, 205, 131, 0.4);
16 const afterColor = new Color(255, 73, 73, 0.4);
17 const options = { beforeColor, afterColor };
18 const { doc1Annotations, doc2Annotations, diffCount } = await documentViewer1.startSemanticDiff(documentViewer2, options);
19 }
20 }
21 documentViewer1.addEventListener('documentLoaded', startCompare);
22 documentViewer2.addEventListener('documentLoaded', startCompare);
23 documentViewer1.loadDocument('https://www.pdftron.com/compare1.pdf');
24 documentViewer2.loadDocument('https://www.pdftron.com/compare2.pdf');
25 });
26 UI.enableFeatures([UI.Feature.MultiViewerMode]);
27});