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 15
/
Copy pathpdftronWebViewer.js
71 lines (61 loc) · 2.07 KB
/
pdftronWebViewer.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
import { LightningElement, track, wire } from 'lwc';
// import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { CurrentPageReference } from 'lightning/navigation';
import { loadScript } from 'lightning/platformResourceLoader';
import libUrl from '@salesforce/resourceUrl/lib';
import myfilesUrl from '@salesforce/resourceUrl/myfiles';
import { registerListener, unregisterAllListeners } from 'c/pubsub';
export default class PdftronWebViewer extends LightningElement {
fullAPI = true;
@wire(CurrentPageReference) pageRef;
connectedCallback() {
registerListener('fileSelected', this.handleFileSelected, this);
}
disconnectedCallback() {
unregisterAllListeners(this);
}
handleFileSelected(file) {
this.iframeWindow.postMessage({type: 'OPEN_DOCUMENT', file: file}, '*')
}
divHeight = 600;
uiInitialized = false;
renderedCallback() {
if (this.uiInitialized) {
return;
}
this.uiInitialized = true;
Promise.all([
loadScript(this, libUrl + '/webviewer.min.js')
])
.then(() => {
this.initUI();
})
.catch(console.error);
}
initUI() {
const myObj = {
libUrl: libUrl,
fullAPI: this.fullAPI,
namespacePrefix: '',
};
const url = myfilesUrl + '/webviewer-demo-annotated.pdf';
// var url = myfilesUrl + '/webviewer-demo-annotated.xod';
// var url = myfilesUrl + '/word.docx';
const viewerElement = this.template.querySelector('div')
const viewer = new WebViewer.Iframe({
path: libUrl, // path to the PDFTron 'lib' folder on your server
custom: JSON.stringify(myObj),
backendType: 'ems',
config: myfilesUrl + '/config_apex.js',
fullAPI: this.fullAPI,
enableFilePicker: this.enableFilePicker,
enableRedaction: this.enableRedaction,
enableMeasurement: this.enableMeasurement,
enableOptimizedWorkers: true,
// l: 'YOUR_LICENSE_KEY_HERE',
}, viewerElement);
viewerElement.addEventListener('ready', () => {
this.iframeWindow = viewerElement.querySelector('iframe').contentWindow
})
}
}