From aae22151216db1595e23b43dac7163112c0d5cab Mon Sep 17 00:00:00 2001 From: DharanyaSakthivel-SF4210 Date: Fri, 28 Mar 2025 15:48:11 +0530 Subject: [PATCH 1/2] ES-825473-Read-JSON-data-set-values-in-form-fields --- ...ad-JSON-data-set-values-in-form-fields.sln | 25 ++++++ .../Data/ReportData.json | 10 +++ .../Output/.gitkeep | 1 + .../Program.cs | 77 +++++++++++++++++++ ...JSON-data-set-values-in-form-fields.csproj | 23 ++++++ 5 files changed, 136 insertions(+) create mode 100644 Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields.sln create mode 100644 Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields/Data/ReportData.json create mode 100644 Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields/Output/.gitkeep create mode 100644 Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields/Program.cs create mode 100644 Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields/Read-JSON-data-set-values-in-form-fields.csproj diff --git a/Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields.sln b/Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields.sln new file mode 100644 index 000000000..fbdc6b380 --- /dev/null +++ b/Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31911.196 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Read-JSON-data-set-values-in-form-fields", "Read-JSON-data-set-values-in-form-fields\Read-JSON-data-set-values-in-form-fields.csproj", "{D3AF529E-DB54-4294-A876-DD42E1E472D0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D3AF529E-DB54-4294-A876-DD42E1E472D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D3AF529E-DB54-4294-A876-DD42E1E472D0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D3AF529E-DB54-4294-A876-DD42E1E472D0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D3AF529E-DB54-4294-A876-DD42E1E472D0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {58137FF9-5AE1-4514-9929-3A8A7DA1DFEB} + EndGlobalSection +EndGlobal diff --git a/Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields/Data/ReportData.json b/Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields/Data/ReportData.json new file mode 100644 index 000000000..3a7d2b755 --- /dev/null +++ b/Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields/Data/ReportData.json @@ -0,0 +1,10 @@ +{ + "Reports": [ + { + "EmployeeID": "1001", + "Name": "Peter", + "PhoneNumber": "+122-2222222", + "Location": "London", + } + ] +} \ No newline at end of file diff --git a/Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields/Output/.gitkeep b/Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields/Output/.gitkeep new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields/Program.cs b/Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields/Program.cs new file mode 100644 index 000000000..1715ef5d7 --- /dev/null +++ b/Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields/Program.cs @@ -0,0 +1,77 @@ +using System.Collections.Generic; +using System.IO; +using Newtonsoft.Json; +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using Syncfusion.DocIORenderer; +using Syncfusion.Pdf; + +namespace Read_JSON_data_set_values_in_form_fields +{ + class Program + { + static void Main(string[] args) + { + // Read and deserialize JSON data. + var jsonString = File.ReadAllText(Path.GetFullPath("Data/ReportData.json")); + var data = JsonConvert.DeserializeObject(jsonString); + + using (WordDocument document = new WordDocument()) + { + ////Get the text from json and replace in Word document + //Adds new section to the document + IWSection section = document.AddSection(); + //Adds new paragraph to the section + WParagraph paragraph = section.AddParagraph().AppendText("General Information") as WParagraph; + section.AddParagraph(); + + AddTextFormField(section, "EmployeeID", data.Reports[0].EmployeeID); + AddTextFormField(section, "Name", data.Reports[0].Name); + AddTextFormField(section, "PhoneNumber", data.Reports[0].PhoneNumber); + AddTextFormField(section, "Location", data.Reports[0].Location); + + //Creates an instance of DocIORenderer. + using (DocIORenderer renderer = new DocIORenderer()) + { + //Converts Word document into PDF document. + using (PdfDocument pdfDocument = renderer.ConvertToPDF(document)) + { + //Saves the PDF file to file system. + using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.pdf"), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) + { + pdfDocument.Save(outputStream); + } + } + } + } + } + + private static void AddTextFormField(IWSection section, string label, string value) + { + WParagraph paragraph = section.AddParagraph() as WParagraph; + IWTextRange text = paragraph.AppendText(label + ": "); + text.CharacterFormat.Bold = true; + + WTextFormField textField = paragraph.AppendTextFormField(null); + textField.Type = TextFormFieldType.RegularText; + textField.CharacterFormat.FontName = "Calibri"; + textField.Text = value; + textField.CalculateOnExit = true; + + section.AddParagraph(); + } + } + public class Reports + { + [JsonProperty("EmployeeID")] public string EmployeeID { get; set; } + [JsonProperty("Name")] public string Name { get; set; } + [JsonProperty("PhoneNumber")] public string PhoneNumber { get; set; } + [JsonProperty("Location")] public string Location { get; set; } + + } + + public class Root + { + [JsonProperty("Reports")] public List Reports { get; set; } + } +} diff --git a/Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields/Read-JSON-data-set-values-in-form-fields.csproj b/Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields/Read-JSON-data-set-values-in-form-fields.csproj new file mode 100644 index 000000000..2b0652ada --- /dev/null +++ b/Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields/Read-JSON-data-set-values-in-form-fields.csproj @@ -0,0 +1,23 @@ + + + + Exe + net8.0 + Read_JSON_data_set_values_in_form_fields + + + + + + + + + + Always + + + Always + + + + From 80baf84c6a1d6a052a9af6791e43520a98597b46 Mon Sep 17 00:00:00 2001 From: DharanyaSakthivel-SF4210 <149999916+DharanyaSakthivel-SF4210@users.noreply.github.com> Date: Fri, 28 Mar 2025 15:51:39 +0530 Subject: [PATCH 2/2] Update Program.cs --- .../Program.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields/Program.cs b/Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields/Program.cs index 1715ef5d7..00ede7268 100644 --- a/Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields/Program.cs +++ b/Form-Fields/Read-JSON-data-set-values-in-form-fields/.NET/Read-JSON-data-set-values-in-form-fields/Program.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using Newtonsoft.Json; using Syncfusion.DocIO; @@ -45,7 +45,9 @@ static void Main(string[] args) } } } - + /// + /// Adds a labeled text form field to the specified section. + /// private static void AddTextFormField(IWSection section, string label, string value) { WParagraph paragraph = section.AddParagraph() as WParagraph; @@ -61,6 +63,10 @@ private static void AddTextFormField(IWSection section, string label, string val section.AddParagraph(); } } + + /// + /// Represents report data with employee details. + /// public class Reports { [JsonProperty("EmployeeID")] public string EmployeeID { get; set; } @@ -69,7 +75,9 @@ public class Reports [JsonProperty("Location")] public string Location { get; set; } } - + /// + /// Root object for deserializing JSON data. + /// public class Root { [JsonProperty("Reports")] public List Reports { get; set; }