diff --git a/Form Designer/Components/Pages/AddButton.md b/Form Designer/Components/Pages/AddButton.md new file mode 100644 index 00000000..1a3e743d --- /dev/null +++ b/Form Designer/Components/Pages/AddButton.md @@ -0,0 +1,25 @@ +@page "/add-button" +@using Syncfusion.Blazor.SfPdfViewer + + + + + +@code { + private SfPdfViewer2 viewer; + private string DocumentPath = "wwwroot/data/Form_Filling_Document.pdf"; + + private async Task AddButtonField() + { + // Create a button field with properties + ButtonField buttonField = new ButtonField() + { + Name = "SubmitButton", + Bounds = new Bound() { X = 100, Y = 190, Width = 150, Height = 40 }, + TooltipText = "Click to submit the form" + }; + + // Add the button field to the PDF document + await viewer.AddFormFieldsAsync(new List { buttonField }); + } +} diff --git a/Form Designer/Components/Pages/AddCheckBox.md b/Form Designer/Components/Pages/AddCheckBox.md new file mode 100644 index 00000000..8a702604 --- /dev/null +++ b/Form Designer/Components/Pages/AddCheckBox.md @@ -0,0 +1,26 @@ +@page "/add-checkbox" +@using Syncfusion.Blazor.SfPdfViewer + + + + + +@code { + private SfPdfViewer2 viewer; + private string DocumentPath = "wwwroot/data/Form_Filling_Document.pdf"; + + private async Task AddCheckBoxField() + { + // Create a checkbox field with properties + CheckBoxField checkBoxField = new CheckBoxField() + { + Name = "AgreeTerms", + Bounds = new Bound() { X = 100, Y = 230, Width = 18, Height = 18 }, + IsChecked = false, + TooltipText = "I agree to the terms" + }; + + // Add the checkbox field to the PDF document + await viewer.AddFormFieldsAsync(new List { checkBoxField }); + } +} diff --git a/Form Designer/Components/Pages/AddCustomData.md b/Form Designer/Components/Pages/AddCustomData.md new file mode 100644 index 00000000..f8e707c7 --- /dev/null +++ b/Form Designer/Components/Pages/AddCustomData.md @@ -0,0 +1,36 @@ +@page "/add-custom-data" +@using Syncfusion.Blazor.SfPdfViewer +@using System.Collections.Generic + + + + + +@code { + private SfPdfViewer2? viewer; + private string DocumentPath = "wwwroot/data/Form_Designer.pdf"; + + private async Task AddFormFieldsWithCustomData() + { + if (viewer == null) return; + + // Define custom metadata + Dictionary customMetadata = new Dictionary + { + { "businessId", "C-1024" }, + { "tags", new[] { "profile", "kiosk" } }, + { "requiredRole", "admin" } + }; + + // Create a TextBox field with custom data + TextBoxField textField = new TextBoxField + { + Name = "Email", + CustomData = customMetadata, + Bounds = new Bound { X = 146, Y = 229, Width = 200, Height = 24 } + }; + + // Add the field to the document + await viewer.AddFormFieldsAsync(new List { textField }); + } +} diff --git a/Form Designer/Components/Pages/AddDropDown.md b/Form Designer/Components/Pages/AddDropDown.md new file mode 100644 index 00000000..bd83b361 --- /dev/null +++ b/Form Designer/Components/Pages/AddDropDown.md @@ -0,0 +1,33 @@ +@page "/add-dropdown" +@using Syncfusion.Blazor.SfPdfViewer + + + + + +@code { + private SfPdfViewer2 viewer; + private string DocumentPath = "wwwroot/data/Form_Filling_Document.pdf"; + + private async Task AddDropDownField() + { + // Create list items for the dropdown + List options = new List() + { + new ListItem() { Name = "Item 1", Value = "item1" }, + new ListItem() { Name = "Item 2", Value = "item2" }, + new ListItem() { Name = "Item 3", Value = "item3" } + }; + + // Create a dropdown field with items + DropDownField dropDownField = new DropDownField() + { + Name = "Country", + Bounds = new Bound() { X = 560, Y = 320, Width = 150, Height = 24 }, + Items = options + }; + + // Add the dropdown field to the PDF document + await viewer.AddFormFieldsAsync(new List { dropDownField }); + } +} diff --git a/Form Designer/Components/Pages/AddListBox.md b/Form Designer/Components/Pages/AddListBox.md new file mode 100644 index 00000000..f1256cbc --- /dev/null +++ b/Form Designer/Components/Pages/AddListBox.md @@ -0,0 +1,33 @@ +@page "/add-listbox" +@using Syncfusion.Blazor.SfPdfViewer + + + + + +@code { + private SfPdfViewer2 viewer; + private string DocumentPath = "wwwroot/data/Form_Filling_Document.pdf"; + + private async Task AddListBoxField() + { + // Create list items for the list box + List items = new List() + { + new ListItem() { Name = "Item 1", Value = "item1" }, + new ListItem() { Name = "Item 2", Value = "item2" }, + new ListItem() { Name = "Item 3", Value = "item3" } + }; + + // Create a list box field with items + ListBoxField listBoxField = new ListBoxField() + { + Name = "States", + Bounds = new Bound() { X = 100, Y = 310, Width = 220, Height = 70 }, + Items = items + }; + + // Add the list box field to the PDF document + await viewer.AddFormFieldsAsync(new List { listBoxField }); + } +} diff --git a/Form Designer/Components/Pages/AddPassword.md b/Form Designer/Components/Pages/AddPassword.md new file mode 100644 index 00000000..2f84c2b7 --- /dev/null +++ b/Form Designer/Components/Pages/AddPassword.md @@ -0,0 +1,27 @@ +@page "/add-password" +@using Syncfusion.Blazor.SfPdfViewer + + + + + +@code { + private SfPdfViewer2 viewer; + private string DocumentPath = "wwwroot/data/Form_Filling_Document.pdf"; + + private async Task AddPasswordField() + { + // Create a password field with properties + PasswordField passwordField = new PasswordField() + { + Name = "AccountPassword", + Bounds = new Bound() { X = 100, Y = 190, Width = 200, Height = 24 }, + IsRequired = true, + MaxLength = 32, + TooltipText = "Enter a secure password" + }; + + // Add the password field to the PDF document + await viewer.AddFormFieldsAsync(new List { passwordField }); + } +} diff --git a/Form Designer/Components/Pages/AddRadioButton.md b/Form Designer/Components/Pages/AddRadioButton.md new file mode 100644 index 00000000..c3eabc49 --- /dev/null +++ b/Form Designer/Components/Pages/AddRadioButton.md @@ -0,0 +1,32 @@ +@page "/add-radiobutton" +@using Syncfusion.Blazor.SfPdfViewer + + + + + +@code { + private SfPdfViewer2 viewer; + private string DocumentPath = "wwwroot/data/Form_Filling_Document.pdf"; + + private async Task AddRadioButtonFields() + { + // Create radio button fields grouped by name 'Gender' + RadioButtonField maleRadioButton = new RadioButtonField() + { + Name = "Gender", + Value = "Male", + Bounds = new Bound() { X = 100, Y = 270, Width = 16, Height = 16 } + }; + + RadioButtonField femaleRadioButton = new RadioButtonField() + { + Name = "Gender", + Value = "Female", + Bounds = new Bound() { X = 160, Y = 270, Width = 16, Height = 16 } + }; + + // Add the radio button fields to the PDF document + await viewer.AddFormFieldsAsync(new List { maleRadioButton, femaleRadioButton }); + } +} diff --git a/Form Designer/Components/Pages/AddSignature.md b/Form Designer/Components/Pages/AddSignature.md new file mode 100644 index 00000000..b62a87b9 --- /dev/null +++ b/Form Designer/Components/Pages/AddSignature.md @@ -0,0 +1,26 @@ +@page "/add-signature" +@using Syncfusion.Blazor.SfPdfViewer + + + + + +@code { + private SfPdfViewer2 viewer; + private string DocumentPath = "wwwroot/data/Form_Filling_Document.pdf"; + + private async Task AddSignatureField() + { + // Create a signature field + SignatureField signatureField = new SignatureField() + { + Name = "Sign", + Bounds = new Bound() { X = 57, Y = 923, Width = 200, Height = 43 }, + TooltipText = "sign Here", + IsRequired = true + }; + + // Add the signature field to the PDF document + await viewer.AddFormFieldsAsync(new List { signatureField }); + } +} diff --git a/Form Designer/Components/Pages/AddTextBox.md b/Form Designer/Components/Pages/AddTextBox.md new file mode 100644 index 00000000..a51e4ec3 --- /dev/null +++ b/Form Designer/Components/Pages/AddTextBox.md @@ -0,0 +1,27 @@ +@page "/add-textbox" +@using Syncfusion.Blazor.SfPdfViewer + + + + + +@code { + private SfPdfViewer2 viewer; + private string DocumentPath = "wwwroot/data/Form_Filling_Document.pdf"; + + private async Task AddTextBox() + { + // Create a text box field with properties + TextBoxField textBoxField = new TextBoxField() + { + Name = "FirstName", + Bounds = new Bound() { X = 100, Y = 150, Width = 200, Height = 24 }, + IsRequired = true, + TooltipText = "Enter your first name", + MaxLength = 40 + }; + + // Add the text box field to the PDF document + await viewer.AddFormFieldsAsync(new List { textBoxField }); + } +} \ No newline at end of file diff --git a/Form Designer/Components/Pages/ApplyFormFieldFlags.md b/Form Designer/Components/Pages/ApplyFormFieldFlags.md new file mode 100644 index 00000000..0165f149 --- /dev/null +++ b/Form Designer/Components/Pages/ApplyFormFieldFlags.md @@ -0,0 +1,45 @@ +@page "/apply-form-field-flags" +@using Syncfusion.Blazor.SfPdfViewer + + + + + + +@code { + // Reference to the PDF Viewer instance + private SfPdfViewer2? viewer; + + // Path to the PDF document to be loaded in the viewer + private string DocumentPath = "wwwroot/data/Form_Designer.pdf"; + + // Method triggered when the document is loaded + private async Task OnDocumentLoaded() + { + if (viewer == null) return; + + List formFields = new List + { + // Read-only Textbox that is not required + new TextBoxField + { + Name = "EmployeeId", + Bounds = new Bound { X = 146, Y = 229, Width = 150, Height = 24 }, + IsReadOnly = true, + IsRequired = false, + Value = "EMP-0001" + }, + // Required Signature field + new SignatureField + { + Name = "ApplicantSign", + Bounds = new Bound { X = 57, Y = 923, Width = 200, Height = 43 }, + IsReadOnly = false, + IsRequired = true, + TooltipText = "Sign to accept the terms" + } + }; + + await viewer.AddFormFieldsAsync(formFields); + } +} diff --git a/Form Designer/Components/Pages/CustomizeTextBox.md b/Form Designer/Components/Pages/CustomizeTextBox.md new file mode 100644 index 00000000..d350314d --- /dev/null +++ b/Form Designer/Components/Pages/CustomizeTextBox.md @@ -0,0 +1,36 @@ +@page "/customize-textbox" +@using Syncfusion.Blazor.SfPdfViewer +@using Syncfusion.Blazor.Buttons + +Apply Textbox Changes + + + + +@code { + private SfPdfViewer2? viewer; + private string DocumentPath = "wwwroot/data/Form_Designer.pdf"; + + private async Task OnEditTextbox() + { + if (viewer == null) return; + + List fields = await viewer.GetFormFieldsAsync(); + + FormFieldInfo? field = fields?.FirstOrDefault(f => f.Name == "FirstName"); + + if (field != null) + { + (field as TextBoxField).Value = "John"; + field.FontFamily = "Courier"; + field.FontSize = 12; + field.Color = "black"; + field.BackgroundColor = "white"; + field.BorderColor = "black"; + field.Thickness = 2; + field.TextAlignment = TextAlignment.Left; + + await viewer.UpdateFormFieldsAsync(new List { field }); + } + } +} \ No newline at end of file diff --git a/Form Designer/Components/Pages/ExtractAllFormFieldValues.md b/Form Designer/Components/Pages/ExtractAllFormFieldValues.md new file mode 100644 index 00000000..cd38f0fc --- /dev/null +++ b/Form Designer/Components/Pages/ExtractAllFormFieldValues.md @@ -0,0 +1,44 @@ +@page "/extract-all-form-field-values" +@using Syncfusion.Blazor.SfPdfViewer +@using Syncfusion.Blazor.Buttons + + + + +Extract All Values + +@code { + private SfPdfViewer2? viewer; + private string DocumentPath = "wwwroot/data/Form_Filling_Document_With_Data.pdf"; + + private async Task ExtractAllFieldValues() + { + if (viewer == null) return; + List formFields = await viewer.GetFormFieldsAsync(); + + foreach (FormFieldInfo field in formFields) + { + if (field is CheckBoxField checkBoxField) + { + Console.WriteLine($"{field.Name}: {checkBoxField.IsChecked}"); + } + else if (field is RadioButtonField radioButtonField) + { + Console.WriteLine($"{field.Name}: {radioButtonField.IsSelected}"); + } + else if (field is TextBoxField textBoxField) + { + Console.WriteLine($"{field.Name}: {textBoxField.Value}"); + } + else if (field is DropDownField dropDownField) + { + ListItem? selectedItem = dropDownField.Items.ElementAtOrDefault(dropDownField.SelectedIndex); + Console.WriteLine($"{field.Name}: {selectedItem?.Value}"); + } + else + { + Console.WriteLine($"{field.Name}: (unknown type)"); + } + } + } +} diff --git a/Form Designer/Components/Pages/ExtractFormDataAfterDocumentLoaded.md b/Form Designer/Components/Pages/ExtractFormDataAfterDocumentLoaded.md new file mode 100644 index 00000000..367ad828 --- /dev/null +++ b/Form Designer/Components/Pages/ExtractFormDataAfterDocumentLoaded.md @@ -0,0 +1,23 @@ +@page "/extract-form-data-after-document-loaded" +@using Syncfusion.Blazor.SfPdfViewer + + + + + +@code { + private SfPdfViewer2? viewer; + private string DocumentPath = "wwwroot/data/Form_Filling_Document_With_Data.pdf"; + + private async Task OnDocumentLoaded() + { + if (viewer == null) return; + + // Access form data right after the PDF loads + List formFields = await viewer.GetFormFieldsAsync(); + TextBoxField? emailField = formFields.FirstOrDefault(field => field is TextBoxField && field.Name == "email") as TextBoxField; + string email = emailField?.Value ?? string.Empty; + + Console.WriteLine($"Email: {email}"); + } +} diff --git a/Form Designer/Components/Pages/FillFormFieldsProgrammatically.md b/Form Designer/Components/Pages/FillFormFieldsProgrammatically.md new file mode 100644 index 00000000..f71118de --- /dev/null +++ b/Form Designer/Components/Pages/FillFormFieldsProgrammatically.md @@ -0,0 +1,43 @@ +@page "/fill-form-fields-programmatically" +@using Syncfusion.Blazor.SfPdfViewer + + + + + + +@code { + SfPdfViewer2? pdfViewer; + + async Task UpdateFormFields() + { + if (pdfViewer == null) + return; + + // Get fields + List formFields = await pdfViewer.GetFormFieldsAsync(); + + if (formFields == null || formFields.Count == 0) + return; + + // Find textbox safely + TextBoxField? textField = formFields + .OfType() + .FirstOrDefault(f => f.Name == "name") + ?? formFields.OfType().FirstOrDefault(); + + if (textField != null) + { + textField.Value = "John Doe"; + textField.TooltipText = "First Name"; + + // Update using SAME TYPE (FormFieldInfo) + await pdfViewer.UpdateFormFieldsAsync(new List() + { + textField + }); + } + } +} diff --git a/Form Designer/Components/Pages/FlattenFormFields.md b/Form Designer/Components/Pages/FlattenFormFields.md new file mode 100644 index 00000000..941546b1 --- /dev/null +++ b/Form Designer/Components/Pages/FlattenFormFields.md @@ -0,0 +1,57 @@ +@page "/flatten-form-fields" +@using Syncfusion.Blazor +@using Syncfusion.Blazor.SfPdfViewer +@using Syncfusion.Blazor.Buttons +@using Syncfusion.Pdf +@using Syncfusion.Pdf.Parsing + +Flatten + + + + +@code { + private SfPdfViewer2? Viewer; + public string DocumentPath { get; set; } = "wwwroot/data/Form_Filling_Document.pdf"; + + private async Task FlattenDownload() + { + if (Viewer is null) return; + + // Get current document from viewer as byte array + byte[] bytes = await Viewer.GetDocumentAsync(); + + // Load into PdfLoadedDocument for flattening + PdfLoadedDocument loadedDocument = new PdfLoadedDocument(bytes); + + // Flatten form fields + if (loadedDocument.Form != null) + { + loadedDocument.Form.Flatten = true; + } + + // Flatten annotations on all pages + foreach (PdfLoadedPage page in loadedDocument.Pages) + { + page.Annotations.Flatten = true; + } + + // Save flattened PDF to byte array + byte[] flattenedBytes; + using (MemoryStream stream = new MemoryStream()) + { + loadedDocument.Save(stream); + flattenedBytes = stream.ToArray(); + } + + loadedDocument.Close(true); + + // Reload flattened document into viewer + await Viewer.LoadAsync(flattenedBytes); + + // Download the flattened PDF + await Viewer.DownloadAsync(); + } +} diff --git a/Form Designer/Components/Pages/GetAllFormFields.md b/Form Designer/Components/Pages/GetAllFormFields.md new file mode 100644 index 00000000..1ee3c972 --- /dev/null +++ b/Form Designer/Components/Pages/GetAllFormFields.md @@ -0,0 +1,20 @@ +@page "/get-all-form-fields" +@using Syncfusion.Blazor.SfPdfViewer +@using Syncfusion.Blazor.Buttons + + + + +Get Form Fields + +@code { + private SfPdfViewer2? viewer; + private string DocumentPath = "wwwroot/data/Form_Filling_Document_With_Data.pdf"; + + private async Task GetAllFormFields() + { + if (viewer == null) return; + List formFields = await viewer.GetFormFieldsAsync(); + Console.WriteLine($"Total form fields: {formFields.Count}"); + } +} diff --git a/Form Designer/Components/Pages/GroupFormFields.md b/Form Designer/Components/Pages/GroupFormFields.md new file mode 100644 index 00000000..a429f363 --- /dev/null +++ b/Form Designer/Components/Pages/GroupFormFields.md @@ -0,0 +1,63 @@ +@page "/group-form-fields" +@using Syncfusion.Blazor.SfPdfViewer + + + + + +@code { + private SfPdfViewer2? viewer; + private string DocumentPath = "wwwroot/data/Form_Designer.pdf"; + + private async Task OnDocumentLoaded() + { + if (viewer == null) return; + + // Create grouped form fields with the same name + List formFields = new List + { + // Textbox group: same name => mirrored value + new TextBoxField + { + Name = "EmployeeId", + Bounds = new Bound { X = 146, Y = 229, Width = 150, Height = 24 } + }, + new TextBoxField + { + Name = "EmployeeId", // same name groups the two widgets + Bounds = new Bound { X = 338, Y = 229, Width = 150, Height = 24 } + }, + + // Radio button group: same name => exclusive selection across the group + new RadioButtonField + { + Name = "Gender", + Bounds = new Bound { X = 148, Y = 289, Width = 18, Height = 18 }, + IsSelected = false + }, + new RadioButtonField + { + Name = "Gender", // grouped with the first + Bounds = new Bound { X = 292, Y = 289, Width = 18, Height = 18 }, + IsSelected = false + }, + + // CheckBox group: same name => mirrored checked state + new CheckBoxField + { + Name = "Subscribe", + Bounds = new Bound { X = 56, Y = 664, Width = 20, Height = 20 }, + IsChecked = false + }, + new CheckBoxField + { + Name = "Subscribe", // grouped with the first + Bounds = new Bound { X = 242, Y = 664, Width = 20, Height = 20 }, + IsChecked = false + } + }; + + // Add the grouped form fields to the PDF document + await viewer.AddFormFieldsAsync(formFields); + } +} diff --git a/Form Designer/Components/Pages/ImportExportFormFieldData.md b/Form Designer/Components/Pages/ImportExportFormFieldData.md new file mode 100644 index 00000000..3fb21ee6 --- /dev/null +++ b/Form Designer/Components/Pages/ImportExportFormFieldData.md @@ -0,0 +1,44 @@ +@page "/import-export-form-field-data" +@using Syncfusion.Blazor.SfPdfViewer +@using Syncfusion.Blazor.Buttons + +Export Data +Import Data + + + + +@code { + // Reference to the SfPdfViewer2 instance + SfPdfViewer2 PdfViewerInstance { get; set; } + + // Stream to store exported form field data in FDF format + MemoryStream FDFStream = new MemoryStream(); + + // List to store form field information + List FormFields = new List(); + + // Exports form field data from the PDF viewer in FDF format + private async void ExportFormFieldData() + { + // Retrieve form field information from the PDF viewer + FormFields = await PdfViewerInstance.GetFormFieldsAsync(); + if (FormFields != null && FormFields.Count > 0) + { + // Export form fields as FDF data + FDFStream = await PdfViewerInstance.ExportFormFieldsAsync(FormFieldDataFormat.Fdf); + } + } + + // Imports form field data from FDF format into the PDF viewer + private async void ImportFormFieldData() + { + if (FDFStream != null) + { + // Import FDF data into the viewer + await PdfViewerInstance.ImportFormFieldsAsync(FDFStream, FormFieldDataFormat.Fdf); + } + } +} diff --git a/Form Designer/Components/Pages/MakeFieldsReadOnly.md b/Form Designer/Components/Pages/MakeFieldsReadOnly.md new file mode 100644 index 00000000..9a6e3bb6 --- /dev/null +++ b/Form Designer/Components/Pages/MakeFieldsReadOnly.md @@ -0,0 +1,43 @@ +@page "/make-fields-readonly" +@using Syncfusion.Blazor.SfPdfViewer + + + + + + +@code { + // Reference to the PDF Viewer instance + private SfPdfViewer2? viewer; + + // Path to the PDF document to be loaded in the viewer + private string DocumentPath = "wwwroot/data/Form_Designer.pdf"; + + // Method triggered when the document is loaded + private async Task OnDocumentLoaded() + { + if (viewer == null) return; + + List formFields = new List + { + // Read-only Textbox + new TextBoxField + { + Name = "EmployeeId", + Bounds = new Bound { X = 146, Y = 229, Width = 150, Height = 24 }, + IsReadOnly = true, + Value = "EMP-0001" + }, + // Read-only Signature field + new SignatureField + { + Name = "ApplicantSign", + Bounds = new Bound { X = 57, Y = 923, Width = 200, Height = 43 }, + IsReadOnly = true, + TooltipText = "Sign to accept the terms" + } + }; + + await viewer.AddFormFieldsAsync(formFields); + } +} diff --git a/Form Designer/Components/Pages/MarkFieldsRequired.md b/Form Designer/Components/Pages/MarkFieldsRequired.md new file mode 100644 index 00000000..e21e5359 --- /dev/null +++ b/Form Designer/Components/Pages/MarkFieldsRequired.md @@ -0,0 +1,45 @@ +@page "/mark-fields-required" +@using Syncfusion.Blazor.SfPdfViewer + + + + + + +@code { + // Reference to the PDF Viewer instance + private SfPdfViewer2? viewer; + + // Path to the PDF document to be loaded in the viewer + private string DocumentPath = "wwwroot/data/Form_Designer.pdf"; + + // Method triggered when the document is loaded + private async Task OnDocumentLoaded() + { + if (viewer == null) return; + + List formFields = new List + { + new TextBoxField + { + Name = "Email", + Bounds = new Bound { X = 146, Y = 260, Width = 220, Height = 24 }, + IsRequired = true, + TooltipText = "Email is required" + } + }; + + await viewer.AddFormFieldsAsync(formFields); + } + + // Validation event handler + private void OnValidateFormFields(ValidateFormFieldsArgs args) + { + Dictionary unfilledFields = args.UnfilledFields; + foreach (KeyValuePair field in unfilledFields) + { + Console.WriteLine($"Field Name: {field.Key}, Default Value: {field.Value}"); + // Further processing of unfilled fields + } + } +} diff --git a/Form Designer/Components/Pages/MoveResizeFormFields.md b/Form Designer/Components/Pages/MoveResizeFormFields.md new file mode 100644 index 00000000..72b69a64 --- /dev/null +++ b/Form Designer/Components/Pages/MoveResizeFormFields.md @@ -0,0 +1,62 @@ +@page "/move-resize-form-fields" +@using Syncfusion.Blazor.SfPdfViewer +@using Syncfusion.Blazor.Buttons + +Add Form Fields +Resize and Move "First Name" + + + + +@code { + private SfPdfViewer2? viewer; + private string DocumentPath = "wwwroot/data/Form_Designer.pdf"; + + private async Task OnAddFormFields() + { + if (viewer == null) return; + + // Create form fields with initial bounds + List formFields = new List + { + new TextBoxField + { + Name = "FirstName", + Bounds = new Bound { X = 146, Y = 229, Width = 150, Height = 24 } + }, + new PasswordField + { + Name = "Password", + Bounds = new Bound { X = 338, Y = 229, Width = 150, Height = 24 } + }, + new SignatureField + { + Name = "SignHere", + Bounds = new Bound { X = 146, Y = 280, Width = 200, Height = 43 } + } + }; + + // Add the form fields to the PDF document + await viewer.AddFormFieldsAsync(formFields); + } + + private async Task OnResizeAndMove() + { + if (viewer == null) return; + + // Retrieve all form fields from the PDF + List fields = await viewer.GetFormFieldsAsync(); + + // Find the "First Name" field + FormFieldInfo? field = fields?.FirstOrDefault(f => f.Name == "FirstName"); + + if (field != null) + { + // Update the bounds (move and resize) + field.Bounds = new Bound { X = 140, Y = 210, Width = 220, Height = 24 }; + + // Apply the changes + await viewer.UpdateFormFieldsAsync(new List { field }); + } + } +} diff --git a/Form Designer/Components/Pages/ReadCheckboxRadioButtonValues.md b/Form Designer/Components/Pages/ReadCheckboxRadioButtonValues.md new file mode 100644 index 00000000..c1ce9619 --- /dev/null +++ b/Form Designer/Components/Pages/ReadCheckboxRadioButtonValues.md @@ -0,0 +1,23 @@ +@page "/read-checkbox-radiobutton-values" +@using Syncfusion.Blazor.SfPdfViewer +@using Syncfusion.Blazor.Buttons + + + + +Read Checkbox Values + +@code { + private SfPdfViewer2? viewer; + private string DocumentPath = "wwwroot/data/Form_Filling_Document_With_Data.pdf"; + + private async Task ReadCheckboxValues() + { + if (viewer == null) return; + List formFields = await viewer.GetFormFieldsAsync(); + List radioButtons = formFields.OfType().Where(field => field.Name == "gender").ToList(); + RadioButtonField? checkedField = radioButtons.FirstOrDefault(field => field.IsSelected); + string fieldName = checkedField?.Name ?? string.Empty; + Console.WriteLine($"Selected radio button: {fieldName}"); + } +} diff --git a/Form Designer/Components/Pages/ReadCustomData.md b/Form Designer/Components/Pages/ReadCustomData.md new file mode 100644 index 00000000..9deb5a4c --- /dev/null +++ b/Form Designer/Components/Pages/ReadCustomData.md @@ -0,0 +1,29 @@ +@page "/read-custom-data" +@using Syncfusion.Blazor.SfPdfViewer + + + + + +@code { + private SfPdfViewer2? viewer; + private string DocumentPath = "wwwroot/data/Form_Designer.pdf"; + + private async Task OnDocumentLoaded() + { + if (viewer == null) return; + + // Get all form fields + List fields = await viewer.GetFormFieldsAsync(); + + // Access custom data from each field + foreach (FormFieldInfo field in fields) + { + Console.WriteLine($"Field: {field.Name}"); + if (field.CustomData != null) + { + Console.WriteLine($"Custom Data: {System.Text.Json.JsonSerializer.Serialize(field.CustomData)}"); + } + } + } +} diff --git a/Form Designer/Components/Pages/ReadDropdownValues.md b/Form Designer/Components/Pages/ReadDropdownValues.md new file mode 100644 index 00000000..eaf1f70c --- /dev/null +++ b/Form Designer/Components/Pages/ReadDropdownValues.md @@ -0,0 +1,54 @@ +@page "/read-dropdown-values" +@using Syncfusion.Blazor.SfPdfViewer +@using Syncfusion.Blazor.Buttons + + + + +Read Dropdown Value + +@code { + private SfPdfViewer2? viewer; + private string DocumentPath = "wwwroot/data/Form_Filling_Document_With_Data.pdf"; + + private async Task ReadDropdownValues() + { + if (viewer == null) return; + + try + { + List formFields = await viewer.GetFormFieldsAsync(); + DropDownField? dropdownField = formFields?.FirstOrDefault(field => field is DropDownField && field.Name == "state") as DropDownField; + + if (dropdownField != null && dropdownField.Items != null && dropdownField.Items.Count > 0) + { + // Read ALL values in dropdown + Console.WriteLine("=== All Dropdown Values ==="); + for (int i = 0; i < dropdownField.Items.Count; i++) + { + Console.WriteLine($"Index {i}: Name = {dropdownField.Items[i].Name}, Value = {dropdownField.Items[i].Value}"); + } + + // Get selected item using SelectedIndex + int selectedIndex = dropdownField.SelectedIndex; + string selectedValue = selectedIndex >= 0 ? dropdownField.Items[selectedIndex].Value : string.Empty; + Console.WriteLine($"\nCurrently Selected: Index={selectedIndex}, Value={selectedValue}"); + + // Update dropdown with new items + dropdownField.Items = new List + { + new ListItem { Name = "USA", Value = "US" }, + new ListItem { Name = "Canada", Value = "CA" }, + new ListItem { Name = "Mexico", Value = "MX" } + }; + dropdownField.SelectedIndex = 0; // Set default selection + + await viewer.UpdateFormFieldsAsync(new List { dropdownField }); + } + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } + } +} diff --git a/Form Designer/Components/Pages/ReadSignatureFieldData.md b/Form Designer/Components/Pages/ReadSignatureFieldData.md new file mode 100644 index 00000000..fcd49d76 --- /dev/null +++ b/Form Designer/Components/Pages/ReadSignatureFieldData.md @@ -0,0 +1,22 @@ +@page "/read-signature-field-data" +@using Syncfusion.Blazor.SfPdfViewer +@using Syncfusion.Blazor.Buttons + + + + +Read Signature Data + +@code { + private SfPdfViewer2? viewer; + private string DocumentPath = "wwwroot/data/Form_Filling_Document_With_Data.pdf"; + + private async Task ReadSignatureData() + { + if (viewer == null) return; + List formFields = await viewer.GetFormFieldsAsync(); + SignatureField? signatureField = formFields.FirstOrDefault(field => field is SignatureField && field.Name == "signature") as SignatureField; + string signatureData = signatureField?.Value ?? string.Empty; + Console.WriteLine($"Signature data: {signatureData}"); + } +} diff --git a/Form Designer/Components/Pages/ReadTextFieldValues.md b/Form Designer/Components/Pages/ReadTextFieldValues.md new file mode 100644 index 00000000..078db81e --- /dev/null +++ b/Form Designer/Components/Pages/ReadTextFieldValues.md @@ -0,0 +1,22 @@ +@page "/read-text-field-values" +@using Syncfusion.Blazor.SfPdfViewer +@using Syncfusion.Blazor.Buttons + + + + +Read Text Field + +@code { + private SfPdfViewer2? viewer; + private string DocumentPath = "wwwroot/data/Form_Filling_Document_With_Data.pdf"; + + private async Task ReadTextFields() + { + if (viewer == null) return; + List formFields = await viewer.GetFormFieldsAsync(); + TextBoxField? nameField = formFields.FirstOrDefault(field => field is TextBoxField && field.Name == "name") as TextBoxField; + string nameValue = nameField?.Value ?? string.Empty; + Console.WriteLine($"Name field value: {nameValue}"); + } +} diff --git a/Form Designer/Components/Pages/UpdateButton.md b/Form Designer/Components/Pages/UpdateButton.md new file mode 100644 index 00000000..74f563ed --- /dev/null +++ b/Form Designer/Components/Pages/UpdateButton.md @@ -0,0 +1,35 @@ +@page "/update-button" +@using Syncfusion.Blazor.SfPdfViewer +@using Syncfusion.Blazor.Buttons + +Edit Button + + + + +@code { + private SfPdfViewer2? viewer; + private string DocumentPath = "wwwroot/data/Form_Designer.pdf"; + + private async Task OnEditButton() + { + if (viewer == null) return; + + List fields = await viewer.GetFormFieldsAsync(); + + FormFieldInfo? field = fields?.FirstOrDefault(f => f.Name == "SubmitButton"); + + if (field != null) + { + field.BackgroundColor = "#008000"; + field.Color = "white"; + field.FontFamily = "Arial"; + field.FontSize = 12; + field.BorderColor = "black"; + field.Thickness = 2; + field.TooltipText = "Click to submit"; + + await viewer.UpdateFormFieldsAsync(new List { field }); + } + } +} diff --git a/Form Designer/Components/Pages/UpdateCheckBox.md b/Form Designer/Components/Pages/UpdateCheckBox.md new file mode 100644 index 00000000..75adc816 --- /dev/null +++ b/Form Designer/Components/Pages/UpdateCheckBox.md @@ -0,0 +1,33 @@ +@page "/update-checkbox" +@using Syncfusion.Blazor.SfPdfViewer +@using Syncfusion.Blazor.Buttons + +Edit CheckBox + + + + +@code { + private SfPdfViewer2? viewer; + private string DocumentPath = "wwwroot/data/Form_Designer.pdf"; + + private async Task OnEditCheckbox() + { + if (viewer == null) return; + + List fields = await viewer.GetFormFieldsAsync(); + + FormFieldInfo? cb = fields?.FirstOrDefault(f => f.Name == "Subscribe"); + + if (cb != null) + { + (cb as CheckBoxField).IsChecked = true; + cb.BackgroundColor = "white"; + cb.BorderColor = "black"; + cb.Thickness = 2; + cb.TooltipText = "Subscribe to newsletter"; + + await viewer.UpdateFormFieldsAsync(new List { cb }); + } + } +} diff --git a/Form Designer/Components/Pages/UpdateCustomData.md b/Form Designer/Components/Pages/UpdateCustomData.md new file mode 100644 index 00000000..8f61de6f --- /dev/null +++ b/Form Designer/Components/Pages/UpdateCustomData.md @@ -0,0 +1,39 @@ +@page "/update-custom-data" +@using Syncfusion.Blazor.SfPdfViewer +@using Syncfusion.Blazor.Buttons +@using System.Collections.Generic + +Update First Field Custom Data + + + + +@code { + private SfPdfViewer2? viewer; + private string DocumentPath = "wwwroot/data/Form_Designer.pdf"; + + private async Task UpdateFirstFieldCustomData() + { + if (viewer == null) return; + + // Get all form fields + List fields = await viewer.GetFormFieldsAsync(); + if (fields.Count == 0) return; + + // Get the first field + FormFieldInfo targetField = fields[0]; + + // Update custom data + Dictionary updatedCustomData = new Dictionary + { + { "group", "profile" }, + { "flags", new[] { "pii", "masked" } }, + { "updatedAt", DateTime.Now.Ticks } + }; + + targetField.CustomData = updatedCustomData; + + // Update the field + await viewer.UpdateFormFieldsAsync(new List { targetField }); + } +} diff --git a/Form Designer/Components/Pages/UpdateDropDown.md b/Form Designer/Components/Pages/UpdateDropDown.md new file mode 100644 index 00000000..1f792953 --- /dev/null +++ b/Form Designer/Components/Pages/UpdateDropDown.md @@ -0,0 +1,38 @@ +@page "/update-dropdown" +@using Syncfusion.Blazor.SfPdfViewer +@using Syncfusion.Blazor.Buttons + +Edit DropDown + + + + +@code { + private SfPdfViewer2? viewer; + private string DocumentPath = "wwwroot/data/FormDesigner_Document.pdf"; + + private async Task UpdateFormField() + { + if (viewer == null) return; + + List formFields = await viewer.GetFormFieldsAsync(); + + // Find only the specific dropdown by name + DropDownField? dropDown = formFields?.FirstOrDefault(f => f.Name == "CountryDropdown" && f is DropDownField) as DropDownField; + if (dropDown != null) + { + dropDown.Items = new List { + new ListItem { Name = "option 1", Value = "Option 1" }, + new ListItem { Name = "option 2", Value = "Option 2" }, + new ListItem { Name = "option 3", Value = "Option 3" } + }; + dropDown.FontFamily = "Courier"; + dropDown.FontSize = 10; + dropDown.Color = "black"; + dropDown.BorderColor = "black"; + dropDown.BackgroundColor = "white"; + + await viewer.UpdateFormFieldsAsync(new List { dropDown }); + } + } +} diff --git a/Form Designer/Components/Pages/UpdateFormFieldFlags.md b/Form Designer/Components/Pages/UpdateFormFieldFlags.md new file mode 100644 index 00000000..3100e1a9 --- /dev/null +++ b/Form Designer/Components/Pages/UpdateFormFieldFlags.md @@ -0,0 +1,46 @@ +@page "/update-form-field-flags" +@using Syncfusion.Blazor.SfPdfViewer + + + + + + +@code { + // Reference to the PDF Viewer instance + private SfPdfViewer2? viewer; + + // Path to the PDF document to be loaded in the viewer + private string DocumentPath = "wwwroot/data/Form_Designer.pdf"; + + // Method triggered when the document is loaded + private async Task OnDocumentLoaded() + { + if (viewer == null) return; + + // 1) Add a sample textbox + List formFields = new List + { + new TextBoxField + { + Name = "Email", + Bounds = new Bound { X = 146, Y = 260, Width = 220, Height = 24 } + } + }; + + await viewer.AddFormFieldsAsync(formFields); + + // 2) Retrieve and update constraint flags + List allFields = await viewer.GetFormFieldsAsync(); + FormFieldInfo? field = allFields.FirstOrDefault(f => f.Name == "Email"); + + if (field is TextBoxField emailField) + { + emailField.IsReadOnly = false; + emailField.IsRequired = true; + emailField.TooltipText = "Enter a valid email"; + + await viewer.UpdateFormFieldsAsync(new List { emailField }); + } + } +} diff --git a/Form Designer/Components/Pages/UpdateListBox.md b/Form Designer/Components/Pages/UpdateListBox.md new file mode 100644 index 00000000..070881f9 --- /dev/null +++ b/Form Designer/Components/Pages/UpdateListBox.md @@ -0,0 +1,38 @@ +@page "/update-listbox" +@using Syncfusion.Blazor.SfPdfViewer +@using Syncfusion.Blazor.Buttons + +Edit ListBox + + + + +@code { + private SfPdfViewer2? viewer; + private string DocumentPath = "wwwroot/data/FormDesigner_Document.pdf"; + + private async Task UpdateFormField() + { + if (viewer == null) return; + + List formFields = await viewer.GetFormFieldsAsync(); + + // Find and update ListBoxField + ListBoxField? listBox = formFields?.FirstOrDefault(f => f.Name == "InterestListBox" && f is ListBoxField) as ListBoxField; + if (listBox != null) + { + listBox.Items = new List { + new ListItem { Name = "item 1", Value = "Item 1" }, + new ListItem { Name = "item 2", Value = "Item 2" }, + new ListItem { Name = "item 3", Value = "Item 3" } + }; + listBox.FontFamily = "Courier"; + listBox.FontSize = 10; + listBox.Color = "black"; + listBox.BorderColor = "black"; + listBox.BackgroundColor = "white"; + + await viewer.UpdateFormFieldsAsync(new List { listBox }); + } + } +} diff --git a/Form Designer/Components/Pages/UpdatePassword.md b/Form Designer/Components/Pages/UpdatePassword.md new file mode 100644 index 00000000..3c9b6cda --- /dev/null +++ b/Form Designer/Components/Pages/UpdatePassword.md @@ -0,0 +1,38 @@ +@page "/update-password" +@using Syncfusion.Blazor.SfPdfViewer +@using Syncfusion.Blazor.Buttons + +Edit PasswordBox + + + + +@code { + private SfPdfViewer2? viewer; + private string DocumentPath = "wwwroot/data/Form_Designer.pdf"; + + private async Task OnEditPassword() + { + if (viewer == null) return; + + List fields = await viewer.GetFormFieldsAsync(); + + FormFieldInfo? field = fields?.FirstOrDefault(f => f.Name == "Password"); + + if (field != null) + { + (field as PasswordField).TooltipText = "Enter your password"; + field.IsReadOnly = false; + field.IsRequired = true; + field.FontFamily = "Courier"; + field.FontSize = 10; + field.Color = "black"; + field.BorderColor = "black"; + field.BackgroundColor = "white"; + field.TextAlignment = TextAlignment.Left; + field.Thickness = 1; + + await viewer.UpdateFormFieldsAsync(new List { field }); + } + } +} diff --git a/Form Designer/Components/Pages/UpdateRadioButton.md b/Form Designer/Components/Pages/UpdateRadioButton.md new file mode 100644 index 00000000..66134782 --- /dev/null +++ b/Form Designer/Components/Pages/UpdateRadioButton.md @@ -0,0 +1,32 @@ +@page "/update-radiobutton" +@using Syncfusion.Blazor.SfPdfViewer +@using Syncfusion.Blazor.Buttons + +Edit RadioButton + + + + +@code { + private SfPdfViewer2? viewer; + private string DocumentPath = "wwwroot/data/Form_Designer.pdf"; + + private async Task OnEditRadio() + { + if (viewer == null) return; + + List fields = await viewer.GetFormFieldsAsync(); + + List? genderRadios = fields?.Where(f => f.Name == "Gender").ToList(); + + if (genderRadios?.Count > 1) + { + (genderRadios[0] as RadioButtonField).IsSelected = false; + (genderRadios[1] as RadioButtonField).IsSelected = true; + genderRadios[1].Thickness = 2; + genderRadios[1].BorderColor = "yellow"; + + await viewer.UpdateFormFieldsAsync(genderRadios); + } + } +} diff --git a/Form Designer/Components/Pages/UpdateSignature.md b/Form Designer/Components/Pages/UpdateSignature.md new file mode 100644 index 00000000..2e49e4da --- /dev/null +++ b/Form Designer/Components/Pages/UpdateSignature.md @@ -0,0 +1,33 @@ +@page "/update-signature" +@using Syncfusion.Blazor.SfPdfViewer +@using Syncfusion.Blazor.Buttons + +Edit Signature + + + + +@code { + private SfPdfViewer2? viewer; + private string DocumentPath = "wwwroot/data/Form_Designer.pdf"; + + private async Task OnEditSignature() + { + if (viewer == null) return; + + List fields = await viewer.GetFormFieldsAsync(); + + FormFieldInfo? sig = fields?.FirstOrDefault(f => f.Name == "Sign"); + + if (sig != null) + { + sig.TooltipText = "Please sign here"; + sig.Thickness = 3; + sig.IsRequired = true; + sig.BackgroundColor = "white"; + sig.BorderColor = "black"; + + await viewer.UpdateFormFieldsAsync(new List { sig }); + } + } +} diff --git a/Form Designer/Components/Pages/UpdateTextBox.md b/Form Designer/Components/Pages/UpdateTextBox.md new file mode 100644 index 00000000..77ae1534 --- /dev/null +++ b/Form Designer/Components/Pages/UpdateTextBox.md @@ -0,0 +1,36 @@ +@page "/update-textbox" +@using Syncfusion.Blazor.SfPdfViewer +@using Syncfusion.Blazor.Buttons + +Apply Textbox Changes + + + + +@code { + private SfPdfViewer2? viewer; + private string DocumentPath = "wwwroot/data/Form_Designer.pdf"; + + private async Task OnEditTextbox() + { + if (viewer == null) return; + + List fields = await viewer.GetFormFieldsAsync(); + + FormFieldInfo? field = fields?.FirstOrDefault(f => f.Name == "FirstName"); + + if (field != null) + { + (field as TextBoxField).Value = "John"; + field.FontFamily = "Courier"; + field.FontSize = 12; + field.Color = "black"; + field.BackgroundColor = "white"; + field.BorderColor = "black"; + field.Thickness = 2; + field.TextAlignment = TextAlignment.Left; + + await viewer.UpdateFormFieldsAsync(new List { field }); + } + } +} diff --git a/Form Designer/Components/Pages/ValidateFormFieldsOnSubmit.md b/Form Designer/Components/Pages/ValidateFormFieldsOnSubmit.md new file mode 100644 index 00000000..39b32483 --- /dev/null +++ b/Form Designer/Components/Pages/ValidateFormFieldsOnSubmit.md @@ -0,0 +1,41 @@ +@page "/validate-form-fields-on-submit" +@using Syncfusion.Blazor.SfPdfViewer +@using Syncfusion.Blazor.Buttons + + + + + +@code { + SfPdfViewer2 Viewer; + + // Method triggered when the document is loaded + private async Task AddFormFields() + { + // Define various form fields with their properties and positions + List formFields = new List + { + new TextBoxField { Name = "TextBox Field", Bounds = new Bound { X = 278, Y = 247, Width = 200, Height = 24 }, IsRequired = true }, + new PasswordField { Name = "Password Field", Bounds = new Bound { X = 278, Y = 323, Width = 200, Height = 24 }, IsRequired = true }, + new SignatureField { Name = "Signature Field", Bounds = new Bound { X = 278, Y = 686, Width = 200, Height = 63 }, IsRequired = true } + }; + + // Add form fields asynchronously to the PDF Viewer + await Viewer.AddFormFieldsAsync(formFields); + } + + // Validation event handler + private void OnValidateFormFields(ValidateFormFieldsArgs args) + { + Dictionary unfilledFields = args.UnfilledFields; + foreach (KeyValuePair field in unfilledFields) + { + Console.WriteLine($"Field Name: {field.Key}, Default Value: {field.Value}"); + // Further processing of unfilled fields + } + } +}