Skip to content

Commit 9472628

Browse files
ES-263733-Generate-QRCode-from-URL
1 parent 9c8fa2d commit 9472628

File tree

5 files changed

+125
-0
lines changed

5 files changed

+125
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31911.196
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Generate-QRCode-from-URL", "Generate-QRCode-from-URL\Generate-QRCode-from-URL.csproj", "{D3AF529E-DB54-4294-A876-DD42E1E472D0}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{D3AF529E-DB54-4294-A876-DD42E1E472D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{D3AF529E-DB54-4294-A876-DD42E1E472D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{D3AF529E-DB54-4294-A876-DD42E1E472D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{D3AF529E-DB54-4294-A876-DD42E1E472D0}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {58137FF9-5AE1-4514-9929-3A8A7DA1DFEB}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Generate_QRCode_from_URL</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
11+
<PackageReference Include="Syncfusion.Pdf.Imaging.Net.Core" Version="*" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<None Update="Data\Template.docx">
16+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
17+
</None>
18+
<None Update="Output\.gitkeep">
19+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
20+
</None>
21+
</ItemGroup>
22+
23+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
using Syncfusion.Drawing;
4+
using Syncfusion.Pdf.Barcode;
5+
using Syncfusion.Pdf.Graphics;
6+
using System.Data;
7+
using System.IO;
8+
9+
namespace Generate_QRCode_from_URL
10+
{
11+
class Program
12+
{
13+
static void Main(string[] args)
14+
{
15+
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath("Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
16+
{
17+
//Loads an existing Word document
18+
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
19+
{
20+
//Uses the mail merge events handler for image fields
21+
document.MailMerge.MergeImageField += new MergeImageFieldEventHandler(MergeField_ProductImage);
22+
//Gets the DataTable
23+
DataTable dataTable = GetDataTable();
24+
//Performs mail merge
25+
document.MailMerge.Execute(dataTable);
26+
27+
// Saves the Word document file to file system
28+
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
29+
{
30+
document.Save(outputStream, FormatType.Docx);
31+
}
32+
}
33+
}
34+
}
35+
36+
/// <summary>
37+
/// Binds the image from QR code during Mail merge process by using MergeImageFieldEventHandler.
38+
/// </summary>
39+
private static void MergeField_ProductImage(object sender, MergeImageFieldEventArgs args)
40+
{
41+
//Binds image from QR code during mail merge
42+
if (args.FieldName == "Website")
43+
{
44+
//Initialize a new PdfQRBarcode instance
45+
PdfQRBarcode QRCode = new PdfQRBarcode();
46+
//Set the XDimension and text for barcode
47+
QRCode.XDimension = 3;
48+
QRCode.Text = args.FieldValue as string;
49+
//Convert the QR code to image
50+
Stream barcodeImage = QRCode.ToImage(new SizeF(300, 300));
51+
barcodeImage.Position = 0;
52+
//Sets QR code image as result
53+
args.ImageStream = barcodeImage;
54+
}
55+
}
56+
/// <summary>
57+
/// Gets the data to perform mail merge.
58+
/// </summary>
59+
/// <returns></returns>
60+
private static DataTable GetDataTable()
61+
{
62+
//Creates new DataTable instance
63+
DataTable table = new DataTable();
64+
//Add columns in DataTable
65+
table.Columns.Add("Name");
66+
table.Columns.Add("Website");
67+
68+
//Add record in new DataRow
69+
DataRow row = table.NewRow();
70+
row["Name"] = "Google";
71+
row["Website"] = "http://www.google.com";
72+
table.Rows.Add(row);
73+
return table;
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)