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..00ede7268 --- /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,85 @@ +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); + } + } + } + } + } + /// + /// 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; + 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(); + } + } + + /// + /// Represents report data with employee details. + /// + 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; } + + } + /// + /// Root object for deserializing JSON data. + /// + 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 + + + +