Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.37216.2 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Insert_Signature_in_Word_Document_through_MailMerge", "Insert_Signature_in_Word_Document_through_MailMerge\Insert_Signature_in_Word_Document_through_MailMerge.csproj", "{EE7EAFF2-30BA-F32D-1FD6-D033BF4D8200}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EE7EAFF2-30BA-F32D-1FD6-D033BF4D8200}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE7EAFF2-30BA-F32D-1FD6-D033BF4D8200}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE7EAFF2-30BA-F32D-1FD6-D033BF4D8200}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE7EAFF2-30BA-F32D-1FD6-D033BF4D8200}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D921C376-3534-4617-B8EF-5CBA4C2FC9DA}
EndGlobalSection
EndGlobal
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>


<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
</ItemGroup>
<ItemGroup>
<None Update="Data\Template.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Data\Signature.gif">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;

namespace Insert_Signature_in_Word_Document_through_MailMerge
{
class Program
{

static void Main(string[] args)
{
// Load the word document
using (FileStream fileStream = new FileStream(Path.GetFullPath("../../../Data/Template.docx"), FileMode.Open, FileAccess.Read))
{
using (WordDocument document = new WordDocument(fileStream, FormatType.Docx))
{
string[] fieldNames = { "Signature" };
string[] fieldValues = { "signature.gif" };

document.MailMerge.MergeImageField += MailMerge_MergeSignature;
//Execute mail merge in the Word document
document.MailMerge.Execute(fieldNames, fieldValues);
using (FileStream outputStream = new FileStream(Path.GetFullPath("../../../Output/Result.docx"), FileMode.Create, FileAccess.Write))
{
//Saves the stream as Word file
document.Save(outputStream, FormatType.Docx);
}
}
}
}
/// <summary>
/// Binds the image from file system and fit within text box during Mail merge process by using MergeImageFieldEventHandler.
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
private static void MailMerge_MergeSignature(object sender, MergeImageFieldEventArgs args)
{
if (args.FieldName == "Signature")
{
string productFileName = args.FieldValue.ToString();
byte[] imageBytes = File.ReadAllBytes(@"Data/" + productFileName);
MemoryStream imageStream = new MemoryStream(imageBytes);
args.ImageStream = imageStream;
// Get the picture to be merged
WPicture picture = args.Picture;

WTextBox textbox = args.CurrentMergeField.OwnerParagraph.OwnerTextBody.Owner as WTextBox;
// check whether the picture is inside the text box
if (textbox != null)
{
// Get the text box format
WTextBoxFormat textBoxFormat = textbox.TextBoxFormat;

if (textBoxFormat != null)
{
// Resize width
if (picture.Width != textBoxFormat.Width)
{
float widthScale = textBoxFormat.Width / picture.Width * 100;
picture.WidthScale = widthScale;
}

// Resize height
if (picture.Height != textBoxFormat.Height)
{
float heightScale = textBoxFormat.Height / picture.Height * 100;
picture.HeightScale = heightScale;
}
}
}
}
}
}
}
Loading