This repository was archived by the owner on Feb 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathApp.js
More file actions
54 lines (45 loc) · 1.53 KB
/
App.js
File metadata and controls
54 lines (45 loc) · 1.53 KB
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
54
import React, { useRef, useEffect } from 'react';
import WebViewer from '@pdftron/webviewer';
import './App.css';
const App = () => {
const viewer = useRef(null);
const selectedAnnotationsRef = useRef(null);
const instanceRef = useRef(null);
useEffect(() => {
WebViewer(
{
path: '/webviewer/lib',
initialDoc: '/files/PDFTRON_about.pdf',
licenseKey: 'your_license_key',
isReadOnly: false,
},
viewer.current,
).then((instance) => {
const { annotationManager } = instance.Core;
const handleAnnotationSelected = annotations => {
selectedAnnotationsRef.current = annotations;
};
instance.UI.enableFeatures([instance.UI.Feature.ContentEdit]);
annotationManager.addEventListener("annotationSelected", handleAnnotationSelected);
instanceRef.current = instance;
});
}, []);
const onStopEditing = async () => {
const { documentViewer } = instanceRef.current.Core;
const contentEditManager = await documentViewer.getContentEditManager();
selectedAnnotationsRef.current.forEach(annotation => {
const contentBoxId = annotation.getCustomData("contentEditBoxId");
const box = contentEditManager.getContentBoxById(contentBoxId);
box.stopContentEditing();
});
}
return (
<div className="App">
<div className="header">React sample
<button onClick={onStopEditing}>Stop editing and save</button>
</div>
<div className="webviewer" ref={viewer}></div>
</div>
);
};
export default App;