Skip to content

Commit 603d80a

Browse files
committed
Update WV constructor to 5.1 version
1 parent 0f7a0e5 commit 603d80a

File tree

4 files changed

+50
-73
lines changed

4 files changed

+50
-73
lines changed

src/App.js

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,71 @@
11
import React, { Component } from 'react';
22
import './App.css';
3-
import WebViewer from './WebViewer';
3+
44

55
class App extends Component {
66
constructor() {
77
super();
8-
this.webviewer = React.createRef();
8+
this.viewer = React.createRef();
9+
this.docViewer = null;
10+
this.annotManager = null;
11+
this.instance = null;
912
}
1013

1114
componentDidMount() {
12-
this.webviewer.current.getElement().addEventListener('ready', this.wvReadyHandler);
13-
this.webviewer.current.getElement().addEventListener('documentLoaded', this.wvDocumentLoadedHandler);
14-
}
15+
window.WebViewer({
16+
path: 'lib',
17+
initialDoc: 'files/webviewer-demo-annotated.pdf'
18+
}, this.viewer.current).then(instance => {
19+
// at this point, the viewer is 'ready'
20+
// call methods from instance, docViewer and annotManager as needed
21+
this.instance = instance;
22+
this.docViewer = instance.docViewer;
23+
this.annotManager = instance.annotManager;
24+
25+
// you can also access major namespaces from the instance as follows:
26+
// var Tools = instance.Tools;
27+
// var Annotations = instance.Annotations;
28+
29+
// now you can access APIs through `this.instance`
30+
this.instance.openElement('notesPanel')
1531

16-
wvReadyHandler = () => {
17-
// now you can access APIs through this.webviewer.current.getInstance()
18-
this.webviewer.current.getInstance().openElement('notesPanel');
19-
// see https://www.pdftron.com/documentation/web/guides/ui/apis for the full list of APIs
20-
21-
// or listen to events from the viewer element
22-
this.webviewer.current.getElement().addEventListener('pageChanged', (e) => {
23-
const [ pageNumber ] = e.detail;
24-
console.log(`Current page is ${pageNumber}`);
25-
});
26-
27-
// or from the docViewer instance
28-
this.webviewer.current.getInstance().docViewer.on('annotationsLoaded', () => {
29-
console.log('annotations loaded');
30-
});
32+
// or listen to events from the viewer element
33+
this.viewer.current.addEventListener('pageChanged', (e) => {
34+
const [ pageNumber ] = e.detail;
35+
console.log(`Current page is ${pageNumber}`);
36+
});
37+
38+
// or from the docViewer instance
39+
this.docViewer.on('annotationsLoaded', () => {
40+
console.log('annotations loaded');
41+
});
42+
43+
this.docViewer.on('documentLoaded', this.wvDocumentLoadedHandler)
44+
})
3145
}
3246

47+
3348
wvDocumentLoadedHandler = () => {
34-
// you can access docViewer object for low-level APIs
35-
const { docViewer } = this.webviewer.current.getInstance();
36-
const annotManager = docViewer.getAnnotationManager();
37-
// and access classes defined in the WebViewer iframe
38-
const { Annotations } = this.webviewer.current.getWindow();
49+
// call methods relating to the loaded document
50+
const { Annotations } = this.instance;
3951
const rectangle = new Annotations.RectangleAnnotation();
4052
rectangle.PageNumber = 1;
4153
rectangle.X = 100;
4254
rectangle.Y = 100;
4355
rectangle.Width = 250;
4456
rectangle.Height = 250;
4557
rectangle.StrokeThickness = 5;
46-
rectangle.Author = annotManager.getCurrentUser();
47-
annotManager.addAnnotation(rectangle);
48-
annotManager.drawAnnotations(rectangle.PageNumber);
49-
// see https://www.pdftron.com/api/web/PDFTron.WebViewer.html for the full list of low-level APIs
58+
rectangle.Author = this.annotManager.getCurrentUser();
59+
this.annotManager.addAnnotation(rectangle);
60+
this.annotManager.drawAnnotations(rectangle.PageNumber);
61+
// see https://www.pdftron.com/api/web/WebViewer.html for the full list of low-level APIs
5062
}
5163

5264
render() {
5365
return (
5466
<div className="App">
5567
<div className="header">React sample</div>
56-
<WebViewer ref={this.webviewer}/>
68+
<div className="webviewer" ref={this.viewer}></div>
5769
</div>
5870
);
5971
}

src/WebViewer.css

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/WebViewer.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/index.css

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,11 @@ html, body, #root {
44
margin: 0;
55
padding: 0;
66
font-family: Arial, Helvetica, sans-serif;
7-
}
7+
}
8+
9+
.webviewer {
10+
flex: 1;
11+
margin: 8px;
12+
-webkit-box-shadow: 1px 1px 10px #999;
13+
box-shadow: 1px 1px 10px #999;
14+
}

0 commit comments

Comments
 (0)