Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.

Commit f9a6d5c

Browse files
committed
Added ability to sync XFDF
1 parent f2b89f2 commit f9a6d5c

File tree

8 files changed

+184
-87
lines changed

8 files changed

+184
-87
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "webviewer",
33
"widgetName": "WebViewer",
4-
"version": "1.4.0",
4+
"version": "1.5.0",
55
"description": "My widget description",
66
"copyright": "2023 PDFTron",
77
"author": "Andrey Safonov",

src/WebViewer.editorPreview.tsx

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,16 @@ declare function require(name: string): string;
66

77
export class preview extends Component<WebViewerPreviewProps> {
88
render(): ReactNode {
9+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
10+
// @ts-ignore
11+
const mx = window.mx;
912
const viewerProps = {
10-
containerHeight: this.props.containerHeight,
11-
fileUrl: this.props.fileUrl,
12-
fileUrlAttribute: this.props.fileUrlAttribute,
13-
fileIdAttribute: this.props.fileIdAttribute,
14-
enableFilePicker: this.props.enableFilePicker,
15-
annotationUser: this.props.annotationUser,
16-
accessibleMode: this.props.accessibleMode,
17-
enableMeasurement: this.props.enableMeasurement,
18-
enableRedaction: this.props.enableRedaction,
19-
enableAnnotations: this.props.enableAnnotations,
20-
xfdfAttribute: this.props.xfdfAttribute,
21-
enableXfdfExportButton: this.props.enableXfdfExportButton,
22-
enableAutoXfdfExport: this.props.enableAutoXfdfExport,
23-
enableAutoXfdfImport: this.props.enableAutoXfdfImport,
24-
loadAsPDF: this.props.loadAsPDF,
25-
highContrastMode: this.props.highContrastMode,
26-
notesInLeftPanel: this.props.notesInLeftPanel,
27-
enabledElements: this.props.enabledElements,
28-
disabledElements: this.props.disabledElements,
29-
selectAnnotationOnCreation: this.props.selectAnnotationOnCreation,
13+
...this.props,
3014
isVisible: this.props.isVisible === "true",
31-
enableDarkMode: this.props.enableDarkMode,
32-
enableFullAPI: this.props.enableFullAPI,
33-
customCss: this.props.customCss,
34-
defaultLanguage: this.props.defaultLanguage,
35-
l: this.props.l,
36-
enableDocumentUpdates: this.props.enableDocumentUpdates,
37-
enableSaveAsButton: this.props.enableSaveAsButton
15+
mx
3816
};
17+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
18+
// @ts-ignore
3919
return <PDFViewer {...viewerProps} />;
4020
}
4121
}

src/WebViewer.tsx

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,14 @@ import "./ui/WebViewer.css";
77

88
export default class WebViewer extends Component<WebViewerContainerProps> {
99
render(): ReactNode {
10+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
11+
// @ts-ignore
12+
const mx = window.mx;
1013
const viewerProps = {
11-
containerHeight: this.props.containerHeight,
12-
fileUrl: this.props.fileUrl,
13-
fileUrlAttribute: this.props.fileUrlAttribute,
14-
fileIdAttribute: this.props.fileIdAttribute,
15-
enableFilePicker: this.props.enableFilePicker,
14+
...this.props,
1615
annotationUser: this.props.annotationUser?.value,
17-
accessibleMode: this.props.accessibleMode,
18-
enableMeasurement: this.props.enableMeasurement,
19-
enableRedaction: this.props.enableRedaction,
20-
enableAnnotations: this.props.enableAnnotations,
21-
xfdfAttribute: this.props.xfdfAttribute,
22-
enableXfdfExportButton: this.props.enableXfdfExportButton,
23-
enableAutoXfdfExport: this.props.enableAutoXfdfExport,
24-
enableAutoXfdfImport: this.props.enableAutoXfdfImport,
25-
loadAsPDF: this.props.loadAsPDF,
26-
highContrastMode: this.props.highContrastMode,
27-
notesInLeftPanel: this.props.notesInLeftPanel,
28-
enabledElements: this.props.enabledElements,
29-
disabledElements: this.props.disabledElements,
30-
selectAnnotationOnCreation: this.props.selectAnnotationOnCreation,
3116
isVisible: this.props.isVisible?.value,
32-
enableDarkMode: this.props.enableDarkMode,
33-
enableFullAPI: this.props.enableFullAPI,
34-
customCss: this.props.customCss,
35-
defaultLanguage: this.props.defaultLanguage,
36-
l: this.props.l,
37-
// Module props
38-
enableDocumentUpdates: this.props.enableDocumentUpdates,
39-
enableSaveAsButton: this.props.enableSaveAsButton
17+
mx
4018
};
4119
return <PDFViewer {...viewerProps} />;
4220
}

src/WebViewer.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,14 @@
175175
<caption>Enable save as</caption>
176176
<description>Adds a button to the header to allow saving a document to the server as a new file. Requires WebViewer module.</description>
177177
</property>
178+
<property key="continueAutoXfdfImport" type="boolean" defaultValue="false">
179+
<caption>Continue Auto XFDF Import</caption>
180+
<description>Continue to import XFDF from the server. This achieves real-time updates at specific intervals. Requires WebViewer module.</description>
181+
</property>
182+
<property key="autoXfdfImportInterval" type="integer" defaultValue="1000">
183+
<caption>Auto Import Interval</caption>
184+
<description>The interval in milliseconds to get XFDF updates from the server for the current file.</description>
185+
</property>
178186
</propertyGroup>
179187
<propertyGroup caption="License">
180188
<property key="l" type="string" required="false">
Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,40 @@
11
class WebViewerModuleClient {
2+
private _mx: any;
3+
constructor(mx: any) {
4+
this._mx = mx;
5+
}
6+
getHeaders(): any {
7+
return {
8+
"X-Csrf-Token": this._mx.session.getConfig("csrftoken")
9+
};
10+
}
211
async checkForModule(): Promise<boolean> {
312
try {
4-
const res = await fetch("/rest/version/v1/modules/webviewer");
13+
const res = await fetch("/rest/version/v1/modules/webviewer", {
14+
headers: this.getHeaders()
15+
});
516
console.info("[Module] Connected:", await res.text());
617
return true;
718
} catch (e) {
819
console.info("[Module] Not detected.");
920
return false;
1021
}
1122
}
23+
async getFileInfo(fileId: string): Promise<any> {
24+
if (!fileId) {
25+
console.warn("Empty file ID was provided.");
26+
return;
27+
}
28+
try {
29+
const res = await fetch(`/rest/documentstore/v1/documents/${fileId}`, {
30+
headers: this.getHeaders()
31+
});
32+
return await res.json();
33+
} catch (e) {
34+
console.info("[Module] Not detected.");
35+
throw e;
36+
}
37+
}
1238
async updateFile(fileId: string, fileData: ArrayBuffer): Promise<void> {
1339
if (!fileId) {
1440
console.warn("Empty file ID was provided.");
@@ -17,25 +43,27 @@ class WebViewerModuleClient {
1743
try {
1844
await fetch(`/rest/documentstore/v1/documents/${fileId}`, {
1945
method: "PUT",
46+
headers: this.getHeaders(),
2047
body: fileData
2148
});
2249
} catch (e) {
2350
console.info("[Module] Failed to save document.", e);
51+
throw e;
2452
}
2553
}
2654
async saveFile(fileData: ArrayBuffer): Promise<string | null | undefined> {
2755
try {
2856
const res = await fetch(`/rest/documentstore/v1/documents`, {
2957
method: "POST",
58+
headers: this.getHeaders(),
3059
body: fileData
3160
});
3261
return await res.text();
3362
} catch (e) {
3463
console.info("[Module] Failed to save document.", e);
64+
throw e;
3565
}
36-
37-
return null;
3866
}
3967
}
4068

41-
export default new WebViewerModuleClient();
69+
export default WebViewerModuleClient;

0 commit comments

Comments
 (0)