In my source document, I have some tags that look like following:
I have to replace them with {MERGEFIELD Image fieldName} at run time, which is fine.
Now while inserting the actual image in event handler
MailMerge_MergeImageField(object sender, MergeImageFieldEventArgs e)
I need some way to get the formatting specified in the origional tag i.e.
Is there a way by which I can attach this additional information of Size and Alignment with Merge Field so that I can get it while inserting the image.
Thanks for your request. I think, you can create a map of field names and formatting, which should be applied, upon replacing tag with merge field in the document. Then when you will execute mail merge, you can get formatting by field name from this map and apply the appropriate formatting on MergeImageField event.
Best regards.
Yes, you can use Hashtable for example, where key is field name and value is object, which represents formatting. Value can be also the original string tag, in such case you need to parse this string on MergeImageField event.
One more query regarding above has come up in my mind.
I am quite likely to have templates which has placeholders like this:
while at some other place in the same document it will look like:
which is two different formatting for same Image code.
What do you suggest for such scenerios as having the Image Code and Formatting in HashTable/Dictionary will not be able to tell me which is the correct formatting for which place.
Thank you for additional information. You are right, in this case Dictionary or Hashtable is useless. We will consider adding more reporting syntax, so you will be able to specify some formatting of images directly in Image merge fields.
In your case, if images are the same for whole document, maybe you can insert them during find and replace process.
Best regards.
Well, it’s not that all images in source template are same
but there is a possibility to have two or three images with same code but different size.
So, I do not know which Image Code is to be replaced with which Image until ExecuteMailMerge,
please guide me how can I know the Image formatting while actually replacing the image in MergeImageField handler.
Thanks for your request. Maybe you can try replacing your placeholders with merge fields, which have different names. In this case, you can use Dictionary approach suggested earlier.
To fill such merge fields from one source field in your data source, I think you can add mapping: https://docs.aspose.com/words/net/advanced-mail-merge-features/
Best regards.
All is working fine with changed merge field name and adding them to MappedDataFields.
One query regarding how it actuall works-
If I have two placeholders with same name - ‘IMAGEC’
So, when I get first, I just add it’s formatting detail to Dictionary object.
When I get second IMAGEC, I change it to IMAGEC1 and add to MappedDataFields as:
and add it’s formatting detail to Dictionary object with the new name.
And at then end MappedDataFields collection only has some selected fields(only those found twice/thrice)
and not all the MergeFields from document.
Now my question is,
When IMailMergeDataSource.GetValue() is being called, does it keep an eye on MappedDataFields collection to get the right datavalue for every FieldName ?
Thanks for your request. Yes, of course, IMailMergeDataSource is aware of MappedDataFields collection and it will return the value from the appropriate field in data source. For instance if you have the following mappings: