Merging images with Text Control Reporting is a very easy job: A placeholder is added at design-time to the template and merged with data from files, databases or memory.

The placeholder object gets a name that should match a data column in your data source. The data column must contain either the binary image data as a byte array, an object of type System.Drawing.Image, a file name, a hex or Base64 encoded string. These options cover most typical image representations in databases.

When the template designer TX Text Control Words is directly connected to a database to provide the proper field names, image placeholders can be directly bound to database fields using the context menu. But this article shows what happends behind the scenes and how to use the SearchPath property of MailMerge to define the image location.

Consider the following XML file as the data source for our merge process:

<?xml version="1.0" encoding="utf-8" ?>
<report>
  <customer>
    <company>Microsoft Corporation</company>
    <company_logo>microsoft_logo.png</company_logo>
  </customer>
  <customer>
    <company>Text Control, LLC</company>
    <company_logo>textcontrol_logo.png</company_logo>
  </customer>
</report>

Each customer entry has two fields: The company name and the file name of a company logo.

In order to create a very simple template for this data source, the following steps are required.

  • Open TX Text Control Words and click the Insert Merge Field button (make sure that you don't open the drop-down button) from the Mailings ribbon tab.

    In the opened dialog box, type in the name of the first field "company" into the Name text box and confirm with OK.

    Merging Images from Files using SearchPath
  • Now, choose Image Placeholder from the Image drop-down button in the Insert ribbon tab. Resize the object to your desired dimension.

    Merging Images from Files using SearchPath
  • Right-click the image, and choose Edit Object Name... from the context menu.

    Merging Images from Files using SearchPath
  • In the opened dialog box, type in the name of the image field in our data source company_logo and confirm with OK.

Given that you created a .NET application and connected an instance of MailMerge with TextControl as described in our quick start tutorial, you can use the SearchPath property to define the location of the images.

  • Open the properties Windows of MailMerge, find the SearchPath property and type in the location of your images.

    Merging Images from Files using SearchPath

In this example, TX Text Control is trying to load the images from these locations:

  • C:\Users\Pictures\microsoft_logo.png
  • C:\Users\Pictures\textcontrol_logo.png

If the SearchPath is empty, the images are expected to be located in the application's root folder.

You can download this simple Visual Studio project and test it on your own. All you need is a trial version of TX Text Control .NET for Windows Forms or TX Text Control Server for ASP.NET. If your run the sample and choose Merge from the Report main menu, you will see the results shown below:

Merging Images from Files using SearchPath