1+ @page " /"
2+
3+ <!-- PDF Viewer component with reference binding and document loading -->
4+ <SfPdfViewer2 @ref =" @viewer" Height =" 800px" Width =" 100%" DocumentPath =" @DocumentPath" >
5+ <PdfViewerEvents DocumentLoaded =" @AddFormFields" ></PdfViewerEvents >
6+ </SfPdfViewer2 >
7+
8+ @code {
9+ // Reference to the PDF Viewer instance
10+ private SfPdfViewer2 viewer ;
11+
12+ // Path to the PDF document
13+ private string DocumentPath = " wwwroot/data/formDesigner_Empty.pdf" ;
14+
15+ // Method triggered when the document is loaded
16+ private async Task AddFormFields ()
17+ {
18+ // Define various form fields with their properties and positions
19+ List <FormFieldInfo > formFields = new List <FormFieldInfo >
20+ {
21+ new ButtonField { Name = " Button Field" , Bounds = new Bound { X = 278 , Y = 157 , Width = 150 , Height = 40 } },
22+ new TextBoxField { Name = " TextBox Field" , Bounds = new Bound { X = 278 , Y = 247 , Width = 200 , Height = 24 } },
23+ new PasswordField { Name = " Password Field" , Bounds = new Bound { X = 278 , Y = 323 , Width = 200 , Height = 24 } },
24+ new CheckBoxField { Name = " CheckBox Field1" , IsChecked = false , Bounds = new Bound { X = 278 , Y = 398 , Width = 20 , Height = 20 } },
25+ new CheckBoxField { Name = " CheckBox Field2" , IsChecked = false , Bounds = new Bound { X = 386 , Y = 398 , Width = 20 , Height = 20 } },
26+ new RadioButtonField { Name = " RadioButton" , Value = " Value1" , IsSelected = false , Bounds = new Bound { X = 278 , Y = 470 , Width = 20 , Height = 20 } },
27+ new RadioButtonField { Name = " RadioButton" , Value = " Value2" , IsSelected = false , Bounds = new Bound { X = 386 , Y = 470 , Width = 20 , Height = 20 } },
28+ new DropDownField { Name = " DropDown Field" , Bounds = new Bound { X = 278 , Y = 536 , Width = 200 , Height = 24 } },
29+ new ListBoxField { Name = " ListBox Field" , Bounds = new Bound { X = 278 , Y = 593 , Width = 198 , Height = 66 } },
30+ new SignatureField { Name = " Signature Field" , Bounds = new Bound { X = 278 , Y = 686 , Width = 200 , Height = 63 } }
31+ };
32+
33+ // Add form fields asynchronously to the PDF Viewer
34+ await viewer .AddFormFieldsAsync (formFields );
35+ }
36+ }
0 commit comments