diff --git a/Mail-Merge/Generate-QRCode-from-URL/.NET/Generate-QRCode-from-URL.sln b/Mail-Merge/Generate-QRCode-from-URL/.NET/Generate-QRCode-from-URL.sln new file mode 100644 index 000000000..57a64a1e3 --- /dev/null +++ b/Mail-Merge/Generate-QRCode-from-URL/.NET/Generate-QRCode-from-URL.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}") = "Generate-QRCode-from-URL", "Generate-QRCode-from-URL\Generate-QRCode-from-URL.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/Mail-Merge/Generate-QRCode-from-URL/.NET/Generate-QRCode-from-URL/Data/Template.docx b/Mail-Merge/Generate-QRCode-from-URL/.NET/Generate-QRCode-from-URL/Data/Template.docx new file mode 100644 index 000000000..f5b9b9f04 Binary files /dev/null and b/Mail-Merge/Generate-QRCode-from-URL/.NET/Generate-QRCode-from-URL/Data/Template.docx differ diff --git a/Mail-Merge/Generate-QRCode-from-URL/.NET/Generate-QRCode-from-URL/Generate-QRCode-from-URL.csproj b/Mail-Merge/Generate-QRCode-from-URL/.NET/Generate-QRCode-from-URL/Generate-QRCode-from-URL.csproj new file mode 100644 index 000000000..9f94fad58 --- /dev/null +++ b/Mail-Merge/Generate-QRCode-from-URL/.NET/Generate-QRCode-from-URL/Generate-QRCode-from-URL.csproj @@ -0,0 +1,23 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net8.0</TargetFramework> + <RootNamespace>Generate_QRCode_from_URL</RootNamespace> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" /> + <PackageReference Include="Syncfusion.Pdf.Imaging.Net.Core" Version="*" /> + </ItemGroup> + + <ItemGroup> + <None Update="Data\Template.docx"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </None> + <None Update="Output\.gitkeep"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </None> + </ItemGroup> + +</Project> diff --git a/Mail-Merge/Generate-QRCode-from-URL/.NET/Generate-QRCode-from-URL/Output/.gitkeep b/Mail-Merge/Generate-QRCode-from-URL/.NET/Generate-QRCode-from-URL/Output/.gitkeep new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/Mail-Merge/Generate-QRCode-from-URL/.NET/Generate-QRCode-from-URL/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Mail-Merge/Generate-QRCode-from-URL/.NET/Generate-QRCode-from-URL/Program.cs b/Mail-Merge/Generate-QRCode-from-URL/.NET/Generate-QRCode-from-URL/Program.cs new file mode 100644 index 000000000..02943e4bc --- /dev/null +++ b/Mail-Merge/Generate-QRCode-from-URL/.NET/Generate-QRCode-from-URL/Program.cs @@ -0,0 +1,76 @@ +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using Syncfusion.Drawing; +using Syncfusion.Pdf.Barcode; +using Syncfusion.Pdf.Graphics; +using System.Data; +using System.IO; + +namespace Generate_QRCode_from_URL +{ + class Program + { + static void Main(string[] args) + { + using (FileStream fileStreamPath = new FileStream(Path.GetFullPath("Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { + //Loads an existing Word document + using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx)) + { + //Uses the mail merge events handler for image fields + document.MailMerge.MergeImageField += new MergeImageFieldEventHandler(MergeField_ProductImage); + //Gets the DataTable + DataTable dataTable = GetDataTable(); + //Performs mail merge + document.MailMerge.Execute(dataTable); + + // Saves the Word document file to file system + using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) + { + document.Save(outputStream, FormatType.Docx); + } + } + } + } + + /// <summary> + /// Binds the image from QR code during Mail merge process by using MergeImageFieldEventHandler. + /// </summary> + private static void MergeField_ProductImage(object sender, MergeImageFieldEventArgs args) + { + //Binds image from QR code during mail merge + if (args.FieldName == "Website") + { + //Initialize a new PdfQRBarcode instance + PdfQRBarcode QRCode = new PdfQRBarcode(); + //Set the XDimension and text for barcode + QRCode.XDimension = 3; + QRCode.Text = args.FieldValue as string; + //Convert the QR code to image + Stream barcodeImage = QRCode.ToImage(new SizeF(300, 300)); + barcodeImage.Position = 0; + //Sets QR code image as result + args.ImageStream = barcodeImage; + } + } + /// <summary> + /// Gets the data to perform mail merge. + /// </summary> + /// <returns></returns> + private static DataTable GetDataTable() + { + //Creates new DataTable instance + DataTable table = new DataTable(); + //Add columns in DataTable + table.Columns.Add("Name"); + table.Columns.Add("Website"); + + //Add record in new DataRow + DataRow row = table.NewRow(); + row["Name"] = "Google"; + row["Website"] = "http://www.google.com"; + table.Rows.Add(row); + return table; + } + } + }