Hello there,
I’m trying to mailMerge an Image into a document. I already read about the IFieldMergingCallback-Interface and also already implemented it.
What I want to do. I get a list of fields and a list of values from Json and I deserialize them into arrays. The value List does contain Images as Base64-Strings sometimes. I take those Strings and Convert them into Images - This is no problem. I already tested it with hard values and also the merge is working.
My Problem:
args.FieldValue is null during the IFieldMergingCallback.ImageFieldMerging-Event and I don’t know why…
The class which is implementing the Interface:
void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e) {
//This is always null
if (e.FieldValue != null) {
byte[] imageBytes = Convert.FromBase64String(e.FieldValue.ToString());
using (var ms = new MemoryStream(imageBytes)) {
ms.Position = 0;
e.Image = Image.FromStream(ms, true, true);
}
}
}
My Main-Class:
string[] fieldList = JsonConvert.DeserializeObject<string[]>(fieldJson);
object[] valueList = JsonConvert.DeserializeObject<object[]>(valueJson);
HandleMergeImageField hmif = new HandleMergeImageField();
//For Mailmerging Images
doc.MailMerge.FieldMergingCallback = hmif;
//Execute MailMerge for field- and valueList
doc.MailMerge.Execute(fieldList, valueList);
Thank you for your help and best regards,
Tim