Skip to content

Commit 725d0a3

Browse files
Modified sample
1 parent 0bbd7cb commit 725d0a3

1 file changed

Lines changed: 20 additions & 15 deletions

File tree

  • Mail-Merge/Insert_Signature_in_Word_Document_through_MailMerge/.NET/Insert_Signature_in_Word_Document_through_MailMerge

Mail-Merge/Insert_Signature_in_Word_Document_through_MailMerge/.NET/Insert_Signature_in_Word_Document_through_MailMerge/Program.cs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,29 @@ private static void MailMerge_MergeSignature(object sender, MergeImageFieldEvent
4242
args.ImageStream = imageStream;
4343
// Get the picture to be merged
4444
WPicture picture = args.Picture;
45-
46-
//Get the text box format
47-
WTextBoxFormat textBoxFormat = (args.CurrentMergeField.OwnerParagraph.OwnerTextBody.Owner as WTextBox).TextBoxFormat;
48-
49-
if (textBoxFormat != null)
45+
46+
WTextBox textbox = args.CurrentMergeField.OwnerParagraph.OwnerTextBody.Owner as WTextBox;
47+
// check whether the picture is inside the text box
48+
if (textbox != null)
5049
{
51-
// Resize width
52-
if (picture.Width != textBoxFormat.Width)
53-
{
54-
float widthScale = textBoxFormat.Width / picture.Width * 100;
55-
picture.WidthScale = widthScale;
56-
}
50+
// Get the text box format
51+
WTextBoxFormat textBoxFormat = textbox.TextBoxFormat;
5752

58-
// Resize height
59-
if (picture.Height != textBoxFormat.Height)
53+
if (textBoxFormat != null)
6054
{
61-
float heightScale = textBoxFormat.Height / picture.Height * 100;
62-
picture.HeightScale = heightScale;
55+
// Resize width
56+
if (picture.Width != textBoxFormat.Width)
57+
{
58+
float widthScale = textBoxFormat.Width / picture.Width * 100;
59+
picture.WidthScale = widthScale;
60+
}
61+
62+
// Resize height
63+
if (picture.Height != textBoxFormat.Height)
64+
{
65+
float heightScale = textBoxFormat.Height / picture.Height * 100;
66+
picture.HeightScale = heightScale;
67+
}
6368
}
6469
}
6570
}

0 commit comments

Comments
 (0)