|
| 1 | +import * as React from 'react'; |
| 2 | +import './index.css'; |
| 3 | +import { |
| 4 | + PdfViewerComponent, Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, BookmarkView, |
| 5 | + ThumbnailView, Print, TextSelection, TextSearch, FormFields, FormDesigner, Inject |
| 6 | +} from '@syncfusion/ej2-react-pdfviewer'; |
| 7 | + |
| 8 | +function App() { |
| 9 | + |
| 10 | + const addField = () => { |
| 11 | + var viewer = document.getElementById('container').ej2_instances[0]; |
| 12 | + viewer.formDesignerModule.addFormField("Textbox", { name: "First Name", bounds: { X: 146, Y: 229, Width: 150, Height: 24 } }); |
| 13 | + viewer.formDesignerModule.addFormField("Textbox", { name: "Middle Name", bounds: { X: 338, Y: 229, Width: 150, Height: 24 } }); |
| 14 | + viewer.formDesignerModule.addFormField('Textbox', { name: 'Last Name', bounds: { X: 530, Y: 229, Width: 150, Height: 24 }, }); |
| 15 | + viewer.formDesignerModule.addFormField('RadioButton', { bounds: { X: 148, Y: 289, Width: 18, Height: 18 }, name: 'Gender', isSelected: false, }); |
| 16 | + viewer.formDesignerModule.addFormField('RadioButton', { bounds: { X: 292, Y: 289, Width: 18, Height: 18 }, name: 'Gender', isSelected: false, }); |
| 17 | + viewer.formDesignerModule.addFormField('Textbox', { name: 'DOB Month', bounds: { X: 146, Y: 320, Width: 35, Height: 24 }, }); |
| 18 | + viewer.formDesignerModule.addFormField('Textbox', { name: 'DOB Date', bounds: { X: 193, Y: 320, Width: 35, Height: 24 }, }); |
| 19 | + viewer.formDesignerModule.addFormField('Textbox', { name: 'DOB Year', bounds: { X: 242, Y: 320, Width: 35, Height: 24 }, }); |
| 20 | + viewer.formDesignerModule.addFormField('InitialField', { name: 'Agree', bounds: { X: 148, Y: 408, Width: 200, Height: 43 }, }); |
| 21 | + viewer.formDesignerModule.addFormField('InitialField', { name: 'Do Not Agree', bounds: { X: 148, Y: 466, Width: 200, Height: 43 }, }); |
| 22 | + viewer.formDesignerModule.addFormField('CheckBox', { name: 'Text Message', bounds: { X: 56, Y: 664, Width: 20, Height: 20 }, isChecked: false, }); |
| 23 | + viewer.formDesignerModule.addFormField('CheckBox', { name: 'Email', bounds: { X: 242, Y: 664, Width: 20, Height: 20 }, isChecked: false, }); |
| 24 | + viewer.formDesignerModule.addFormField('CheckBox', { name: 'Appointment Reminder', bounds: { X: 56, Y: 740, Width: 20, Height: 20 }, isChecked: false, }); |
| 25 | + viewer.formDesignerModule.addFormField('CheckBox', { name: 'Request for Customerservice', bounds: { X: 56, Y: 778, Width: 20, Height: 20 }, isChecked: false, }); |
| 26 | + viewer.formDesignerModule.addFormField('CheckBox', { name: 'Information Billing', bounds: { X: 290, Y: 740, Width: 20, Height: 20 }, isChecked: false, }); |
| 27 | + viewer.formDesignerModule.addFormField('Textbox', { name: 'My Email', bounds: { X: 146, Y: 850, Width: 200, Height: 24 }, }); |
| 28 | + viewer.formDesignerModule.addFormField('Textbox', { name: 'My Phone', bounds: { X: 482, Y: 850, Width: 200, Height: 24 }, }); |
| 29 | + viewer.formDesignerModule.addFormField('SignatureField', { name: 'Sign', bounds: { X: 57, Y: 923, Width: 200, Height: 43 }, }); |
| 30 | + viewer.formDesignerModule.addFormField('Textbox', { name: 'DOS Month', bounds: { X: 386, Y: 923, Width: 35, Height: 24 }, }); |
| 31 | + viewer.formDesignerModule.addFormField('Textbox', { name: 'DOS Date', bounds: { X: 434, Y: 923, Width: 35, Height: 24 }, }); |
| 32 | + viewer.formDesignerModule.addFormField('Textbox', { name: 'DOS Year', bounds: { X: 482, Y: 923, Width: 35, Height: 24 }, }); |
| 33 | + }; |
| 34 | + |
| 35 | + const editField = () => { |
| 36 | + var viewer = document.getElementById('container').ej2_instances[0]; |
| 37 | + const field = viewer.formFieldCollections.find(f => f.name === "First Name"); |
| 38 | + if (field) { |
| 39 | + viewer.formDesignerModule.updateFormField(field, { |
| 40 | + value: 'Peter', |
| 41 | + backgroundColor: '#e0f7fa', |
| 42 | + borderColor: '#00796b', |
| 43 | + fontColor: '#004d40' |
| 44 | + }); |
| 45 | + } |
| 46 | + }; |
| 47 | + |
| 48 | + const deleteField = () => { |
| 49 | + var viewer = document.getElementById('container').ej2_instances[0]; |
| 50 | + viewer.formDesignerModule.deleteFormField(viewer.formFieldCollections[2]); |
| 51 | + }; |
| 52 | + |
| 53 | + function downloadClicked() { |
| 54 | + var viewer = document.getElementById('container').ej2_instances[0]; |
| 55 | + viewer.download(); |
| 56 | + } |
| 57 | + |
| 58 | + return ( |
| 59 | + <div> |
| 60 | + {/* Header Section */} |
| 61 | + <div style={{ |
| 62 | + display: 'flex', |
| 63 | + justifyContent: 'space-between', |
| 64 | + alignItems: 'center', |
| 65 | + padding: '10px 20px', |
| 66 | + backgroundColor: '#f5f5f5', |
| 67 | + borderBottom: '1px solid #ddd' |
| 68 | + }}> |
| 69 | + <h2 style={{ margin: 0 }}>Syncfusion PDF Viewer </h2> |
| 70 | + <div> |
| 71 | + <button onClick={addField} style={{ marginRight: '10px' }}>Add Field</button> |
| 72 | + <button onClick={editField} style={{ marginRight: '10px' }}>Edit Field</button> |
| 73 | + <button onClick={deleteField} style={{ marginRight: '10px' }}>Delete Field</button> |
| 74 | + <button onClick={downloadClicked}>Download</button> |
| 75 | + </div> |
| 76 | + </div> |
| 77 | + {/* PDF Viewer Section */} |
| 78 | + <div className='control-section'> |
| 79 | + <PdfViewerComponent |
| 80 | + id="container" |
| 81 | + documentPath="https://cdn.syncfusion.com/content/pdf/form-designer.pdf" |
| 82 | + resourceUrl="https://cdn.syncfusion.com/ej2/31.2.2/dist/ej2-pdfviewer-lib" |
| 83 | + style={{ height: '700px' }} |
| 84 | + > |
| 85 | + <Inject services={[ |
| 86 | + Toolbar, Magnification, Navigation, Annotation, LinkAnnotation, |
| 87 | + BookmarkView, ThumbnailView, Print, TextSelection, TextSearch, |
| 88 | + FormFields, FormDesigner |
| 89 | + ]} /> |
| 90 | + </PdfViewerComponent> |
| 91 | + </div> |
| 92 | + </div> |
| 93 | + ); |
| 94 | +} |
| 95 | + |
| 96 | +export default App; |
0 commit comments