TX Text Control Source Code Library

How to merge images into MS Word templates

TX Text Control image merging

Merging images is required in many templates: Company logos in invoices, pictures of employees in HR reports or signature images in letters. These images can't be part of the template as they have to be merged dynamically.

With the release of TX Text Control .NET Server 16.0, the MailMerge class comes with this feature out of the box. It is possible to pass an image path with the merge data or an image can be added dynamically in the new ImageFieldMerged event.

Image fields are regular merge fields with a special format:

TX Text Control image field format

'image:' is the identifier followed by the name of this field. In this sample, all image fields are merged with the same image in the ImageFieldMerged event:

void mailMerge_ImageFieldMerged(object sender, TXTextControl.DocumentServer.MailMerge.ImageFieldMergedEventArgs e) { if (pictureBox1.Image == null) return; // add the image from the PictureBox TXTextControl.Image img = new TXTextControl.Image(pictureBox1.Image); e.Image = img; }

Try it yourself using the code example. Just start the application, load the shipped template, select an image and click Merge. The minimum requirements for this sample application are TX Text Control Server for ASP.NET (incl. Windows Forms) trial version and Visual Studio .NET 2008.

Call us: +1 704-544-7445 (United States)





Buy Now

About Text Control

Founded in 1991, Text Control is an award-winning Visual Studio Industry Partner and leading vendor of word processing and reporting components for Microsoft development technologies. The products help thousands of developers add comprehensive word processing functionality to their applications. Text Control is 100% self-owned and independent of all investor decisions. Customers benefit from these years of experience, large user-base, and at the same time, appreciate developing with a mature, reliable product.

SD Times 100SD Times 100SD Times 100SD Times 100SD Times 100SD Times 100Visual Studio 2015 Launch PartnerVisual Studio 2013 Launch PartnerVisual Studio 2012 Launch PartnerVisual Studio Partner