Skip to content

Commit da1ba7c

Browse files
Merge pull request #390 from SyncfusionExamples/ES-262924-Mail-merge-Word-to-PDF
ES-262924- Add the sample Mail-merge-Word-to-PDF
2 parents 7433625 + 152b4b0 commit da1ba7c

File tree

7 files changed

+179
-0
lines changed

7 files changed

+179
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35527.113 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mail-merge-Word-to-PDF", "Mail-merge-Word-to-PDF\Mail-merge-Word-to-PDF.csproj", "{C7C9CB0A-077F-4617-B958-EF13E70AE542}"
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+
{C7C9CB0A-077F-4617-B958-EF13E70AE542}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{C7C9CB0A-077F-4617-B958-EF13E70AE542}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{C7C9CB0A-077F-4617-B958-EF13E70AE542}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{C7C9CB0A-077F-4617-B958-EF13E70AE542}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
5+
</startup>
6+
</configuration>
Binary file not shown.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{C7C9CB0A-077F-4617-B958-EF13E70AE542}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>Mail_merge_Word_to_PDF</RootNamespace>
10+
<AssemblyName>Mail-merge-Word-to-PDF</AssemblyName>
11+
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="Syncfusion.Compression.Base, Version=29.1462.33.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
37+
<HintPath>..\packages\Syncfusion.Compression.Base.29.1.33\lib\net462\Syncfusion.Compression.Base.dll</HintPath>
38+
</Reference>
39+
<Reference Include="Syncfusion.DocIO.Base, Version=29.1462.33.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
40+
<HintPath>..\packages\Syncfusion.DocIO.WinForms.29.1.33\lib\net462\Syncfusion.DocIO.Base.dll</HintPath>
41+
</Reference>
42+
<Reference Include="Syncfusion.DocToPdfConverter.Base, Version=29.1462.33.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
43+
<HintPath>..\packages\Syncfusion.DocToPDFConverter.WinForms.29.1.33\lib\net462\Syncfusion.DocToPdfConverter.Base.dll</HintPath>
44+
</Reference>
45+
<Reference Include="Syncfusion.Licensing, Version=29.1462.33.0, Culture=neutral, PublicKeyToken=632609b4d040f6b4, processorArchitecture=MSIL">
46+
<HintPath>..\packages\Syncfusion.Licensing.29.1.33\lib\net462\Syncfusion.Licensing.dll</HintPath>
47+
</Reference>
48+
<Reference Include="Syncfusion.OfficeChart.Base, Version=29.1462.33.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
49+
<HintPath>..\packages\Syncfusion.OfficeChart.Base.29.1.33\lib\net462\Syncfusion.OfficeChart.Base.dll</HintPath>
50+
</Reference>
51+
<Reference Include="Syncfusion.Pdf.Base, Version=29.1462.33.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
52+
<HintPath>..\packages\Syncfusion.Pdf.WinForms.29.1.33\lib\net462\Syncfusion.Pdf.Base.dll</HintPath>
53+
</Reference>
54+
<Reference Include="System" />
55+
<Reference Include="System.Core" />
56+
<Reference Include="System.Xml.Linq" />
57+
<Reference Include="System.Data.DataSetExtensions" />
58+
<Reference Include="Microsoft.CSharp" />
59+
<Reference Include="System.Data" />
60+
<Reference Include="System.Net.Http" />
61+
<Reference Include="System.Xml" />
62+
</ItemGroup>
63+
<ItemGroup>
64+
<Compile Include="Program.cs" />
65+
<Compile Include="Properties\AssemblyInfo.cs" />
66+
</ItemGroup>
67+
<ItemGroup>
68+
<None Include="App.config" />
69+
<None Include="packages.config" />
70+
</ItemGroup>
71+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
72+
</Project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Syncfusion.DocIO.DLS;
2+
using Syncfusion.DocToPDFConverter;
3+
using Syncfusion.Pdf;
4+
using System.IO;
5+
6+
namespace Mail_merge_Word_to_PDF
7+
{
8+
internal class Program
9+
{
10+
static void Main(string[] args)
11+
{
12+
// Opens the template Word document
13+
using (WordDocument document = new WordDocument("../../Data/Template.docx"))
14+
{
15+
// Defines the merge field names and corresponding values
16+
string[] fieldNames = new string[] { "EmployeeId", "Name", "Phone", "City" };
17+
string[] fieldValues = new string[] { "1001", "Peter", "+122-2222222", "London" };
18+
19+
// Performs the mail merge operation
20+
document.MailMerge.Execute(fieldNames, fieldValues);
21+
22+
// Converts the merged Word document to PDF
23+
using (DocToPDFConverter render = new DocToPDFConverter())
24+
{
25+
using (PdfDocument pdfDocument = render.ConvertToPDF(document))
26+
{
27+
// Saves the PDF document to the specified file path
28+
using (FileStream docStream1 = new FileStream(Path.GetFullPath(@"../../Result.pdf"), FileMode.Create, FileAccess.Write))
29+
{
30+
pdfDocument.Save(docStream1);
31+
}
32+
}
33+
}
34+
}
35+
}
36+
}
37+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Mail-merge-Word-to-PDF")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Mail-merge-Word-to-PDF")]
13+
[assembly: AssemblyCopyright("Copyright © 2025")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("c7c9cb0a-077f-4617-b958-ef13e70ae542")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
[assembly: AssemblyVersion("1.0.0.0")]
33+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Syncfusion.Compression.Base" version="29.1.33" targetFramework="net462" />
4+
<package id="Syncfusion.DocIO.WinForms" version="29.1.33" targetFramework="net462" />
5+
<package id="Syncfusion.DocToPDFConverter.WinForms" version="29.1.33" targetFramework="net462" />
6+
<package id="Syncfusion.Licensing" version="29.1.33" targetFramework="net462" />
7+
<package id="Syncfusion.OfficeChart.Base" version="29.1.33" targetFramework="net462" />
8+
<package id="Syncfusion.Pdf.WinForms" version="29.1.33" targetFramework="net462" />
9+
</packages>

0 commit comments

Comments
 (0)