-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
102 lines (99 loc) · 2.61 KB
/
index.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
import { createRoot } from 'react-dom/client';
import './index.css';
import * as React from 'react';
import {
PdfViewerComponent,
Toolbar,
Magnification,
Navigation,
LinkAnnotation,
BookmarkView,
ThumbnailView,
Print,
TextSelection,
TextSearch,
Annotation,
FormFields,
FormDesigner,
PageOrganizer,
Inject,
} from '@syncfusion/ej2-react-pdfviewer';
function Default() {
let viewer;
React.useEffect(() => {
// Load Google Fonts using Web Font Loader
if (window.WebFont) {
window.WebFont.load({
google: {
families: ['Roboto:300,400,700', 'Caveat:300,400,700'], // Add required fonts
},
loading: function () {
console.log('Fonts are being loaded');
},
active: function () {
console.log('Fonts have been rendered');
},
inactive: function () {
console.error('Failed to load fonts');
},
});
}
}, []);
const documentLoad = (args) => {
//var viewer = document.getElementById('container').ej2_instances[0];
//To add form fields
// viewer.formDesignerModule.addFormField('SignatureField', {
// bounds: { X: 146, Y: 200, Width: 150, Height: 70 },
// });
//To retrieve form fields
const formFields = viewer.retrieveFormFields();
const field = formFields[0];
//To update form fields value
if(field){
field.value = 'Tiago';
field.fontName = 'Caveat';
viewer?.updateFormFieldsValue(field);
}
};
return (
<div>
<div className="control-section">
</div>
{/* Render the PDF Viewer */}
<PdfViewerComponent
ref={(scope) => {
viewer = scope;
}}
id="container"
documentLoad={documentLoad}
documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
resourceUrl="https://cdn.syncfusion.com/ej2/23.2.6/dist/ej2-pdfviewer-lib"
style={{ height: '640px' }}
signatureFieldSettings={{
typeSignatureFonts: ['Caveat'],
}}
>
<Inject
services={[
Toolbar,
Magnification,
Navigation,
LinkAnnotation,
BookmarkView,
ThumbnailView,
Print,
TextSelection,
TextSearch,
Annotation,
FormFields,
FormDesigner,
PageOrganizer,
]}
/>
</PdfViewerComponent>
</div>
);
}
export default Default;
const root = createRoot(document.getElementById('sample'));
root.render(<Default />);