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

Commit b27fb63

Browse files
committed
Adjded ability to auto import XFDF
1 parent cfc6f6c commit b27fb63

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

src/WebViewer.editorPreview.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class preview extends Component<WebViewerPreviewProps> {
1919
xfdfAttribute: this.props.xfdfAttribute,
2020
enableXfdfExportButton: this.props.enableXfdfExportButton,
2121
enableAutoXfdfExport: this.props.enableAutoXfdfExport,
22+
enableAutoXfdfImport: this.props.enableAutoXfdfImport,
2223
loadAsPDF: this.props.loadAsPDF,
2324
highContrastMode: this.props.highContrastMode,
2425
notesInLeftPanel: this.props.notesInLeftPanel,

src/WebViewer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default class WebViewer extends Component<WebViewerContainerProps> {
2020
xfdfAttribute: this.props.xfdfAttribute,
2121
enableXfdfExportButton: this.props.enableXfdfExportButton,
2222
enableAutoXfdfExport: this.props.enableAutoXfdfExport,
23+
enableAutoXfdfImport: this.props.enableAutoXfdfImport,
2324
loadAsPDF: this.props.loadAsPDF,
2425
highContrastMode: this.props.highContrastMode,
2526
notesInLeftPanel: this.props.notesInLeftPanel,

src/WebViewer.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@
9191
<caption>Enable Auto XFDF Export</caption>
9292
<description>Enable automatic saving of the annotation XFDF when annotations change.</description>
9393
</property>
94+
<property key="enableAutoXfdfImport" type="boolean" defaultValue="false">
95+
<caption>Enable Auto XFDF Import</caption>
96+
<description>Enable automatic importing of the annotation XFDF when the document loads.</description>
97+
</property>
9498
</propertyGroup>
9599
</propertyGroup>
96100
<propertyGroup caption="UI">

src/components/PDFViewer.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface InputProps {
1616
xfdfAttribute?: any;
1717
enableXfdfExportButton: boolean;
1818
enableAutoXfdfExport: boolean;
19+
enableAutoXfdfImport: boolean;
1920
loadAsPDF?: boolean;
2021
highContrastMode?: boolean;
2122
notesInLeftPanel?: boolean;
@@ -142,7 +143,15 @@ const PDFViewer: React.FC<InputProps> = props => {
142143
"The XFDF attribute is read-only. Please check the user permissions or allow the data source to be editable."
143144
);
144145
} else {
145-
const updateXfdfAttribute = async (): Promise<void> => {
146+
const updateXfdfAttribute = async (
147+
_annotations: Event | any[],
148+
_action: string,
149+
info: any
150+
): Promise<void> => {
151+
// Skip import events
152+
if (info && info.imported) {
153+
return;
154+
}
146155
const doc = Core.documentViewer.getDocument();
147156
if (!doc) {
148157
return;
@@ -180,6 +189,13 @@ const PDFViewer: React.FC<InputProps> = props => {
180189
currentFileId = props.fileId;
181190
}
182191
});
192+
193+
Core.documentViewer.setDocumentXFDFRetriever(async () => {
194+
// Only auto import when we are loading from a file entity
195+
if (currentFileId && props.enableAutoXfdfImport) {
196+
return props.xfdfAttribute.value;
197+
}
198+
});
183199
});
184200
}, [viewer]);
185201

typings/WebViewerProps.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface WebViewerContainerProps {
4747
xfdfAttribute?: EditableValue<string>;
4848
enableXfdfExportButton: boolean;
4949
enableAutoXfdfExport: boolean;
50+
enableAutoXfdfImport: boolean;
5051
isVisible?: EditableValue<boolean>;
5152
containerHeight: string;
5253
enableDarkMode: boolean;
@@ -81,6 +82,7 @@ export interface WebViewerPreviewProps {
8182
onExportXfdf: {} | null;
8283
enableXfdfExportButton: boolean;
8384
enableAutoXfdfExport: boolean;
85+
enableAutoXfdfImport: boolean;
8486
isVisible: string;
8587
containerHeight: string;
8688
enableDarkMode: boolean;

0 commit comments

Comments
 (0)