1+ @page " /events"
2+
3+ @* Export Form fields as JSON stream *@
4+ <SfButton OnClick =" ExportFields" >Export Form Fields</SfButton >
5+ @* Import Form fields as JSON stream *@
6+ <SfButton OnClick =" ImportFields" >Import Form Fields</SfButton >
7+ <!-- PDF Viewer component with reference binding and Form Designer Events -->
8+ <SfPdfViewer2 @ref =" @viewer" Height =" 800px" Width =" 100%" DocumentPath =" @DocumentPath" EnableFormFieldsValidation =" true" IsDesignerModeChanged =" IsDesignerModeChanged" >
9+ <PdfViewerEvents
10+ FormFieldAdding =" @OnFormFieldAdding" FormFieldAdded =" @OnFormFieldAdded" FormFieldDeleted =" @OnFormFieldDeleted" FormFieldClick =" @OnFormFieldClicked"
11+ FormFieldDoubleClick =" @OnFormFieldDoubleClicked" FormFieldSelected =" @OnFormFieldSelected" FormFieldUnselected =" @OnFormFieldUnSelected" FormFieldResized =" @OnFormFieldResized"
12+ ValidateFormFields =" @OnFormFieldValidated" FormFieldFocusIn =" @OnFormFieldFocusIn" FormFieldFocusOut =" @OnFormFieldFocusOut" FormFieldMouseEnter =" @OnFormFieldMouseEnter"
13+ FormFieldMouseLeave =" @OnFormFieldMouseLeave" FormFieldPropertyChanged =" @OnFormFieldPropertyChanged" FormFieldsExporting =" OnFormFieldsExporting" FormFieldsImporting =" OnFormFieldsImporting"
14+ FormFieldsExported =" OnFormFieldsExported" FormFieldsImported =" OnFormFieldsImported" FormFieldsExportFailed =" OnFormFieldsExportFailed" FormFieldsImportFailed =" OnFormFieldsImportFailed" >
15+ </PdfViewerEvents >
16+ </SfPdfViewer2 >
17+
18+ <div >Triggered event:@eventName </div >
19+
20+ @code {
21+ // Reference to the PDF Viewer instance
22+ private SfPdfViewer2 ? viewer ;
23+ private string eventName = " " ;
24+
25+ // Path to the PDF document
26+ private string DocumentPath = " wwwroot/data/formDesigner_Document.pdf" ;
27+ Stream JSONStream = new MemoryStream ();
28+
29+ void OnFormFieldAdding (FormFieldAddEventArgs args )
30+ {
31+ // Access details about the adding form field
32+ eventName = " FormFieldAdding" ;
33+ Console .WriteLine ($" Form Field being added: {args .Field .Name }" );
34+ // args.Cancel = true; // Prevents the form field from being added
35+ // Additional processing logic
36+ }
37+
38+ void OnFormFieldAdded (FormFieldAddedEventArgs args )
39+ {
40+ // Access details about the added form field
41+ eventName = " FormFieldAdded" ;
42+ Console .WriteLine ($" Form Field added: {args .Field .Name }" );
43+ // Additional processing logic
44+ }
45+ void OnFormFieldDeleted (FormFieldDeletedEventArgs args )
46+ {
47+ // Access details about the deleted form field
48+ eventName = " FormFieldDeleted" ;
49+ Console .WriteLine ($" Form field deleted: {args .Field .Name }" );
50+ // Implement additional logic, such as logging or UI updates
51+ }
52+
53+ void OnFormFieldClicked (FormFieldClickArgs args )
54+ {
55+ // Access details about the clicked form field
56+ eventName = " FormFieldClicked" ;
57+ Console .WriteLine ($" Form Field clicked: {args .FormField .Name }" );
58+ // Additional processing logic
59+ }
60+
61+ void OnFormFieldDoubleClicked (FormFieldDoubleClickEventArgs args )
62+ {
63+ // Access details about the double clicked form field
64+ eventName = " FormFieldDoubleClicked" ;
65+ Console .WriteLine ($" Form field double clicked: {args .Field .Name }" );
66+ // Implement additional logic, such as logging or UI updates
67+ }
68+
69+ void OnFormFieldSelected (FormFieldSelectedEventArgs args )
70+ {
71+ // Access details about the selected form field
72+ eventName = " FormFieldSelected" ;
73+ Console .WriteLine ($" Form field selected: {args .Field .Name }" );
74+ // Implement additional logic, such as logging or UI updates
75+ }
76+
77+ void OnFormFieldUnSelected (FormFieldUnselectedEventArgs args )
78+ {
79+ // Access details about the unselected form field
80+ eventName = " FormFieldUnSelected" ;
81+ Console .WriteLine ($" Form field unselected: {args .Field .Name }" );
82+ // Implement additional logic, such as logging or UI updates
83+ }
84+
85+ void OnFormFieldResized (FormFieldResizedEventArgs args )
86+ {
87+ // Access details about the resized form field
88+ eventName = " FormFieldResized" ;
89+ Console .WriteLine ($" Form field resized: {args .Field .Name }" );
90+ // Implement additional logic, such as logging or UI updates
91+ }
92+ void OnFormFieldValidated (ValidateFormFieldsArgs args )
93+ {
94+ // Access details about the validated form field
95+ eventName = " ValidateFormFields" ;
96+ Console .WriteLine ($" Form field Validated: {args .Fields [0 ].Name }" );
97+ // Implement additional logic, such as logging or UI updates
98+ }
99+
100+ void OnFormFieldFocusIn (FormFieldFocusInEventArgs args )
101+ {
102+ // Access details about the focused in form field
103+ eventName = " FormFieldFocusIn" ;
104+ Console .WriteLine ($" Form field focused in: {args .Field .Name }" );
105+ // Implement additional logic, such as logging or UI updates
106+ }
107+
108+ void OnFormFieldFocusOut (FormFieldFocusOutEventArgs args )
109+ {
110+ // Access details about the focused out form field
111+ eventName = " FormFieldFocusOut" ;
112+ Console .WriteLine ($" Form field focused out: {args .Field .Name }" );
113+ // Implement additional logic, such as logging or UI updates
114+ }
115+
116+ void OnFormFieldMouseEnter (FormFieldMouseEnterEventArgs args )
117+ {
118+ // Access details about the mouse entered form field
119+ eventName = " FormFieldMouseEnter" ;
120+ Console .WriteLine ($" Form field Mouse entered: {args .Field .Name }" );
121+ // Implement additional logic, such as logging or UI updates
122+ }
123+
124+ void OnFormFieldMouseLeave (FormFieldMouseLeaveEventArgs args )
125+ {
126+ // Access details about the mouse leaved form field
127+ eventName = " FormFieldMouseLeave" ;
128+ Console .WriteLine ($" Form field Mouse leaved: {args .Field .Name }" );
129+ // Implement additional logic, such as logging or UI updates
130+ }
131+
132+ void OnFormFieldPropertyChanged (FormFieldPropertyChangedEventArgs args )
133+ {
134+ // Access details about the property changed form field
135+ eventName = " FormFieldPropertyChanged" ;
136+ Console .WriteLine ($" Form field property changed: {args .NewValue }" );
137+ // Implement additional logic, such as logging or UI updates
138+ }
139+
140+ void IsDesignerModeChanged (bool args )
141+ {
142+ // Check the state of Designer mode
143+ eventName = " IsDesignerModeChanged" ;
144+ Console .WriteLine ($" Designer mode is: {args }" );
145+ // Implement additional logic, such as logging or UI updates
146+ }
147+
148+ private async void ExportFields ()
149+ {
150+ // Export form fields as JSON Stream
151+ if (viewer != null )
152+ {
153+ JSONStream = await viewer .ExportFormFieldsAsync (FormFieldDataFormat .Json );
154+ }
155+ }
156+ private async void ImportFields ()
157+ {
158+ // Import form fields as JSON Stream
159+ if (JSONStream != null && viewer != null )
160+ {
161+ // Import JSON data into the viewer
162+ await viewer .ImportFormFieldsAsync (JSONStream , FormFieldDataFormat .Json );
163+ }
164+ }
165+
166+ void OnFormFieldsExporting (FormFieldsExportEventArgs args )
167+ {
168+ eventName = " FormFieldsExporting" ;
169+ Console .WriteLine ($" Form fields are being exported" );
170+ // args.Cancel = true; // Cancels the export process
171+ // Implement additional logic, such as logging or UI updates
172+ }
173+
174+ void OnFormFieldsImporting (FormFieldsImportEventArgs args )
175+ {
176+ eventName = " FormFieldsImporting" ;
177+ Console .WriteLine ($" Form fields are being imported" );
178+ // args.Cancel = true; //cancels the import process
179+ // Implement additional logic, such as logging or UI updates
180+ }
181+
182+ void OnFormFieldsExported (FormFieldsExportedEventArgs args )
183+ {
184+ eventName = " FormFieldsExported" ;
185+ Console .WriteLine ($" Form fields are exported Successfully" );
186+ // Implement additional logic, such as logging or UI updates
187+ }
188+
189+ void OnFormFieldsImported (FormFieldsImportedEventArgs args )
190+ {
191+ eventName = " FormFieldsImported" ;
192+ Console .WriteLine ($" Form fields are imported Successfully" );
193+ // Implement additional logic, such as logging or UI updates
194+ }
195+
196+ void OnFormFieldsExportFailed (FormFieldsExportFailedEventArgs args )
197+ {
198+ eventName = " FormFieldsExportFailed" ;
199+ Console .WriteLine ($" Form field export is failed: {args .ErrorDetails }" );
200+ // Implement additional logic, such as logging or UI updates
201+ }
202+
203+ void OnFormFieldsImportFailed (FormFieldsImportFailedEventArgs args )
204+ {
205+ eventName = " FormFieldsImportFailed" ;
206+ Console .WriteLine ($" Form field Import is failed: {args .ErrorDetails }" );
207+ // Implement additional logic, such as logging or UI updates
208+ }
209+ }
0 commit comments