-
Notifications
You must be signed in to change notification settings - Fork 56
42194-How to insert signature in Word document through mail merge? #555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...d_Document_through_MailMerge/.NET/Insert_Signature_in_Word_Document_through_MailMerge.sln
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 added
BIN
+15.9 KB
...ugh_MailMerge/.NET/Insert_Signature_in_Word_Document_through_MailMerge/Data/Template.docx
Binary file not shown.
Binary file added
BIN
+2.92 KB
...rge/.NET/Insert_Signature_in_Word_Document_through_MailMerge/Data/signature.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions
26
...ord_Document_through_MailMerge/Insert_Signature_in_Word_Document_through_MailMerge.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 added
BIN
+15.1 KB
...ugh_MailMerge/.NET/Insert_Signature_in_Word_Document_through_MailMerge/Output/Result.docx
Binary file not shown.
1 change: 1 addition & 0 deletions
1
...ugh_MailMerge/.NET/Insert_Signature_in_Word_Document_through_MailMerge/Output/gitkeep.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| |
68 changes: 68 additions & 0 deletions
68
...ent_through_MailMerge/.NET/Insert_Signature_in_Word_Document_through_MailMerge/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| 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; | ||
|
|
||
| //Get the text box format | ||
| WTextBoxFormat textBoxFormat = (args.CurrentMergeField.OwnerParagraph.OwnerTextBody.Owner as WTextBox).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; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If owner is not textbox then it will throw null exception