Images can be merged in the same way as merge fields in a report template. Placeholders are added at design time and merged with data from files, databases, or memory. An image object can be added to the template with a specified name. 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.

Image Placeholders

The following screenshot shows a template with a merge field for an image:

Merging image placeholders in TX Text Control

Starting with TX Text Control 32.0 SP3, image placeholders can be merged with SVG data.

Merging SVG Image Placeholders

The JSON data below is an example of how an SVG image can be part of the merge data. The SVG image must be provided in its pure XML format and must not be encoded as a base64 string.

[
{
"invoice": {
"company": "Company Name",
"address": "1234 Street Name",
"svgimagedata": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"346.667\" height=\"36.817\" xml:space=\"preserve\"><style>.s1{fill:#102b66}.s2{fill:#9d9d9c}</style><switch><g><path class=\"s1\" d=\"M45.563.672h4.286l9.583 14.545L69.1.672h4.201L61.449 18.073l12.189 17.653h-4.372l-9.834-14.88-9.921 14.88h-4.285l12.188-17.653zM10.424 4.12v31.606H6.977V4.12H0V.672h17.486V4.12zM25.892 19.84v12.524h14.794v3.361h-18.24V.672h18.24v3.45H25.892v12.27h14.794v3.448zM85.658 4.12v31.606h-3.447V4.12H75.15V.672h17.484V4.12zM174.93.672h10.847l12.858 20.176V.672h8.323v35.223h-8.742L183.253 11.77v24.125h-8.323zM241.843.672v6.809H230.83v28.414h-9.079V7.481H210.74V.672zM260 7.231c-.588-.085-1.261-.085-2.017-.085h-3.279v9.5h2.775c.925 0 1.765 0 2.521-.087v7.988l-1.176-1.598h-4.121v12.945h-9.078V.672h14.374v6.559zm5.382 4.202c0-.841-.169-1.598-.504-2.271-.422-.588-1.012-1.092-1.933-1.428-.589-.252-1.262-.421-2.106-.504h-.838V.672h.838c2.106 0 3.87.169 5.383.335 1.513.254 2.942.758 4.204 1.598 1.342.758 2.438 1.766 3.192 3.027.756 1.261 1.179 2.857 1.179 4.707 0 2.606-.589 4.708-1.852 6.39-1.177 1.596-2.942 3.025-5.126 4.117l11.768 15.047h-11.095L260 24.546v-7.988c.422 0 .756-.082 1.094-.082 1.008-.169 1.85-.506 2.436-1.01.675-.504 1.094-1.007 1.429-1.598.254-.587.423-1.426.423-2.435M297.994 36.65h-.082c-5.633 0-10.088-1.68-13.282-4.959-3.194-3.277-4.792-7.732-4.792-13.365 0-5.715 1.598-10.171 4.792-13.449 3.194-3.279 7.649-4.875 13.282-4.875h.082v6.64c-1.175 0-2.269.169-3.277.589-1.008.419-1.933 1.094-2.773 2.017-.84.923-1.429 2.1-1.933 3.615-.504 1.596-.758 3.361-.758 5.463s.254 3.865.671 5.296c.508 1.514 1.18 2.69 1.935 3.615.756.925 1.683 1.681 2.777 2.102 1.09.421 2.184.671 3.359.671v6.64zm17.991-18.325c0 5.633-1.598 10.088-4.788 13.365-3.196 3.279-7.652 4.959-13.202 4.959v-6.64c1.094 0 2.187-.25 3.196-.671 1.09-.504 2.017-1.177 2.775-2.102.922-1.092 1.511-2.354 2.015-3.782.422-1.513.589-3.194.589-5.213 0-2.102-.252-3.867-.756-5.38-.419-1.429-1.094-2.691-1.848-3.531-.842-1.007-1.767-1.681-2.775-2.1a8.564 8.564 0 0 0-3.196-.589V.001c5.55 0 9.921 1.596 13.202 4.875 3.19 3.278 4.788 7.734 4.788 13.449M330.36.672v28.412h16.307v6.811h-25.386V.672zM109.691 34.976c.336.142.668.292 1.017.412 1.43.506 2.942.84 4.54 1.01.842.167 1.766.167 2.69.167 1.849 0 3.194-.083 4.203-.25a29.911 29.911 0 0 0 3.279-.758c.841-.25 1.681-.504 2.521-.925.338-.083.673-.25 1.094-.419.422-.254.924-.421 1.428-.673v-6.113c-6.416 2.602-13.374 5.136-20.772 7.549z\"/><path d=\"M112.726 27.403c-.926-.84-1.681-2.017-2.355-3.53-.588-1.512-.924-3.279-.924-5.548 0-.756 0-1.513.085-2.269.17-1.094.421-2.185.757-3.111.588-1.429 1.345-2.69 2.269-3.529.842-.842 1.682-1.429 2.69-1.852.168 0 .336-.083.506-.165 1.175-.422 2.352-.589 3.613-.589 1.175 0 2.269.167 3.279.504 1.007.336 1.933.756 2.773 1.261.841.506 1.598 1.01 2.186 1.429.084.083.084.083.168.083.422.421.925.756 1.261 1.094.167.083.251.167.336.252h1.092v-8.49c-.42-.254-.923-.421-1.428-.673-.251-.084-.588-.252-.839-.336-.842-.421-1.851-.758-2.859-1.008-1.01-.254-2.102-.504-3.361-.675C120.797.084 119.451 0 118.02 0c-1.007 0-1.931.083-2.772.165-1.681.17-3.193.591-4.624 1.095-2.267.842-4.202 2.1-5.716 3.615-1.596 1.681-2.773 3.613-3.615 5.884-.839 2.269-1.261 4.792-1.261 7.565v.504c0 2.775.506 5.213 1.261 7.398.645 1.58 1.422 2.985 2.367 4.211a336.56 336.56 0 0 0 9.146-2.976c-.025-.02-.054-.035-.08-.058zM143.239 14.375c.084-.419.253-.84.337-1.262.503-1.513 1.177-2.773 1.934-3.615.841-1.008 1.765-1.68 2.772-2.1 1.012-.336 2.102-.588 3.279-.588 1.178 0 2.27.252 3.28.673.169.07.321.19.485.274 2.504-1.751 4.62-3.473 6.268-5.141-2.756-1.61-6.101-2.448-10.032-2.448-.757 0-1.43 0-2.102.084-2.351.169-4.369.673-6.22 1.431-1.933.84-3.614 1.932-5.042 3.446-.421.419-.757.84-1.178 1.346-2.353 3.109-3.614 7.144-3.614 12.02 0 .345.025.671.037 1.007a180.412 180.412 0 0 0 9.713-4.578c.03-.18.048-.373.083-.549z\" class=\"s2\"/><path d=\"M159.547 13.113c.504 1.514.756 3.279.756 5.381 0 2.017-.252 3.698-.671 5.129-.419 1.511-1.092 2.773-1.935 3.782-.838 1.01-1.764 1.681-2.772 2.102-1.094.503-2.186.673-3.363.673s-2.268-.17-3.361-.673c-1.01-.421-1.934-1.092-2.774-2.019-.758-.925-1.347-2.1-1.85-3.615-.168-.335-.253-.755-.337-1.175-.052-.261-.082-.549-.126-.819a222.416 222.416 0 0 1-8.605 3.868c.797 2.356 2.019 4.399 3.689 6.112 1.428 1.514 3.11 2.606 5.042 3.446 2.355 1.01 5.128 1.512 8.322 1.512 5.632 0 10.089-1.596 13.282-4.959 3.277-3.277 4.875-7.732 4.875-13.365 0-4.398-.989-8.069-2.977-11.032-2.055 1.779-4.481 3.591-7.281 5.422.027.08.06.149.086.23z\" class=\"s1\"/></g><foreignObject><img src=\"./text_control_logo.png\"/></foreignObject></switch></svg>"
}
}
]
view raw data.json hosted with ❤ by GitHub

The following code shows how to merge the JSON data with the template:

string jsonData = File.ReadAllText("data.json");
using (MailMerge mailMerge = new MailMerge())
{
mailMerge.TextComponent = textControl1;
mailMerge.MergeJsonData(jsonData);
}
view raw test.cs hosted with ❤ by GitHub

The following screenshot shows the result of the merged template:

Merging SVG image placeholders in TX Text Control

Conclusion

Images can be merged in the same way as merge fields in a report template. Placeholders are added at design time and merged with data from files, databases, or memory. Starting with TX Text Control 32.0 SP3, image placeholders can be merged with SVG data.