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 20
/
Copy pathApp.js
167 lines (148 loc) · 5.97 KB
/
App.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import React, { useRef, useEffect, useState } from 'react';
import SearchContainer from './components/SearchContainer';
import { ReactComponent as ZoomIn } from './assets/icons/ic_zoom_in_black_24px.svg';
import { ReactComponent as ZoomOut } from './assets/icons/ic_zoom_out_black_24px.svg';
import { ReactComponent as AnnotationRectangle } from './assets/icons/ic_annotation_square_black_24px.svg';
import { ReactComponent as AnnotationRedact } from './assets/icons/ic_annotation_add_redact_black_24px.svg';
import { ReactComponent as AnnotationApplyRedact} from './assets/icons/ic_annotation_apply_redact_black_24px.svg';
import { ReactComponent as Search } from './assets/icons/ic_search_black_24px.svg';
import { ReactComponent as Select } from './assets/icons/ic_select_black_24px.svg';
import { ReactComponent as EditContent } from './assets/icons/ic_edit_page_24px.svg';
import { ReactComponent as AddParagraph } from './assets/icons/ic_paragraph_24px.svg';
import { ReactComponent as AddImageContent } from './assets/icons/ic_add_image_24px.svg';
import './App.css';
const App = () => {
const viewer = useRef(null);
const scrollView = useRef(null);
const searchTerm = useRef(null);
const searchContainerRef = useRef(null);
const [documentViewer, setDocumentViewer] = useState(null);
const [annotationManager, setAnnotationManager] = useState(null);
const [searchContainerOpen, setSearchContainerOpen] = useState(false);
const [isInContentEditMode, setIsInContentEditMode] = useState(false);
const Annotations = window.Core.Annotations;
// if using a class, equivalent of componentDidMount
useEffect(() => {
const Core = window.Core;
Core.setWorkerPath('/webviewer');
Core.enableFullPDF();
const documentViewer = new Core.DocumentViewer();
documentViewer.setScrollViewElement(scrollView.current);
documentViewer.setViewerElement(viewer.current);
documentViewer.enableAnnotations();
documentViewer.loadDocument('/files/demo.pdf');
setDocumentViewer(documentViewer);
documentViewer.addEventListener('documentLoaded', () => {
console.log('document loaded');
documentViewer.setToolMode(documentViewer.getTool(Core.Tools.ToolNames.EDIT));
setAnnotationManager(documentViewer.getAnnotationManager());
});
}, []);
const zoomOut = () => {
documentViewer.zoomTo(documentViewer.getZoomLevel() - 0.25);
};
const zoomIn = () => {
documentViewer.zoomTo(documentViewer.getZoomLevel() + 0.25);
};
const startEditingContent = () => {
const contentEditManager = documentViewer.getContentEditManager();
contentEditManager.startContentEditMode();
setIsInContentEditMode(true);
}
const endEditingContent = () => {
setIsInContentEditMode(false);
documentViewer.setToolMode(documentViewer.getTool(window.Core.Tools.ToolNames.EDIT));
const contentEditManager = documentViewer.getContentEditManager();
contentEditManager.endContentEditMode();
}
const addParagraph = () => {
if (isInContentEditMode) {
const addParagraphTool = documentViewer.getTool(window.Core.Tools.ToolNames.ADD_PARAGRAPH);
documentViewer.setToolMode(addParagraphTool);
} else {
alert('Content Edit mode is not enabled.')
}
};
const addImageContent = () => {
if (isInContentEditMode) {
const addImageContentTool = documentViewer.getTool(window.Core.Tools.ToolNames.ADD_IMAGE_CONTENT);
documentViewer.setToolMode(addImageContentTool);
} else {
alert('Content Edit mode is not enabled.')
}
};
const createRectangle = () => {
documentViewer.setToolMode(documentViewer.getTool(window.Core.Tools.ToolNames.RECTANGLE));
};
const selectTool = () => {
documentViewer.setToolMode(documentViewer.getTool(window.Core.Tools.ToolNames.EDIT));
};
const createRedaction = () => {
documentViewer.setToolMode(documentViewer.getTool(window.Core.Tools.ToolNames.REDACTION));
};
const applyRedactions = async () => {
const annotationManager = documentViewer.getAnnotationManager();
annotationManager.enableRedaction();
await annotationManager.applyRedactions();
};
return (
<div className="App">
<div id="main-column">
<div className="center" id="tools">
<button onClick={zoomOut}>
<ZoomOut />
</button>
<button onClick={zoomIn}>
<ZoomIn />
</button>
<button onClick={startEditingContent} title="Switch to edit mode">
<EditContent />
</button>
<button onClick={addParagraph} title="Add new paragraph">
<AddParagraph />
</button>
<button onClick={addImageContent} title="Add new content image">
<AddImageContent />
</button>
<button onClick={endEditingContent} title="End edit mode">
Finish Editing
</button>
<button onClick={createRectangle}>
<AnnotationRectangle />
</button>
<button onClick={createRedaction} title="Create Redaction">
<AnnotationRedact />
</button>
<button onClick={applyRedactions} title="Apply Redactions">
<AnnotationApplyRedact />
</button>
<button onClick={selectTool}>
<Select />
</button>
<button
onClick={() => {
// Flip the boolean
setSearchContainerOpen(prevState => !prevState);
}}
>
<Search />
</button>
</div>
<div className="flexbox-container" id="scroll-view" ref={scrollView}>
<div id="viewer" ref={viewer}></div>
</div>
</div>
<div className="flexbox-container">
<SearchContainer
Annotations={Annotations}
annotationManager={annotationManager}
documentViewer={documentViewer}
searchTermRef={searchTerm}
searchContainerRef={searchContainerRef}
open={searchContainerOpen}
/>
</div>
</div>
);
};
export default App;