Thanks for your inquiry. In reference to the mentioned example, event handler IFieldMergingCallback.imageFieldMerging() , used to insert pictures dynamically from data base, has been set in start of mailMergeImageFromBlob() method . You can amend the solution according to you need i.e. data source and template field names.
// Set up the event handler for image fields.
doc.getMailMerge().setFieldMergingCallback(new HandleMergeImageFieldFromBlob());
To can use mail merge wizard to create MS Word template or insert a mail merge field using Ctrl+f9 and update the field properties according to you need.
Secondly, you can set image size while inserting image to the fields. Please check following link, it would be helpful in acomplashing mail merge.
Hopefully it will fullfil your purpose. If still you have any confusion then please share your sample code and template. So we will have a closer look into and suggest you accordingly.
Please feel free to contact us for any further assitance.
Dear Jens,
Please find attached mail merge template. Hopefully it will server your purpose.
Please let us know for any further assitance. We are always glad to help you.
Best Regards,
Thanks for your inquiry. You can add a null value condition to avoid this issue as shown in following code snippet. Secondly please verify that your database contains that referenced image field i.e. PhotoBLOB . Moreover, please check following link related to image mail merging.
https://forum.aspose.com/t/57593
public void imageFieldMerging(ImageFieldMergingArgs e) throws Exception {
if (e.getFieldValue() != null) {
// The field value is a byte array, just cast it and create a stream on it.
ByteArrayInputStream imageStream = new ByteArrayInputStream((byte[]) e.getFieldValue());
// Now the mail merge engine will retrieve the image from the stream.
e.setImageStream(imageStream);
}
}
Hopefully it will fulfill your requirement. Please feel free to contact us for any further assistance.
I think we talk of two different subjects. I dont talk of the execution moment when my code is running. I talk of the template designing moment:
Our users can create their own templates with our prorgam. So we create a RTF file for using it as datasource of the template, so the user can select mergefields from der mergefield-dialog in Word. That’s all running.
Now we would like to have a possibility for our users that they can insert a mergefield from the mailmerge-fields list in Word and they will see at that moment an dummy image at the position where the mergefield was inserted.
Offtopic: If I understand correctly the following steps are execute at the moment of executing mailmerge:
Document.getMailMerge().execute*() is called with a map of fields<–>values
These values conatains i.e the image data or any another datasource providing the
requested values
fieldMerging(FieldMergingArgs args) is called for additional logic for each single found
field
imageFieldMerging(ImageFieldMergingArgs args) is called for every found Image:XXX
MergeField. ImageFieldMergingArgs.getFieldValue() contains the data set in step 1
Is that correct?
Thank you again very much!
Kind regards
Jens Boeckel
------------------------------
Abacus Research AG
Switzerland
Hi Jens,
Sorry for the inconvenience. Could you please share some more details/sample code for generating that dummy image template. So we will have close look into it and suggest you accordingly.
Secondly, about mail merging execution your understating is correct.
Please feel free to contact us for any further assistance.
Best Regards,
as attachment you’ll find a sample datasource rtf document in which the field IMAGE_DOUBLEDOT_AnyImage should be the image field where the image data should be displayed.
In our code we transform these fields with DOUBLEDOT to fields with ‘:’ before performing mailmerge. This is done with TableStart: and TableEnd: as well.
Thank you again!
Kind regards,
Jens Boeckel
------------------------------
Abacus Research AG
Switzerland
Hi Jense,
Please accept my apology for the inconvenience faced. In reference to template building for preview, Ms Word supports INCLUDEPICTURE field for image. Whereas, currently Aspose.Words supports only IMAGE field in its mail merging feature. I have linked your request with a similar issue logged in our bug tracking system, WORDSNET-6715. The issue logged for INCLUDEPICTURE mail merge request in Aspose.Words. You will be notified as soon as it is resolved.
Best Regards,
I think there is some confusion of what the actual issue is here. It sounds more like you are asking for a feature of Microsoft Word and not Aspose.Words. Note that Aspose.Words is a class library which is completely separate from Microsoft Word and does not provide any UI at all.
You stated you want use a datasource for mail merge in Microsoft Word and have the user able to insert a field from this list and see a preview of the document. I think this isn’t directly possible through Microsoft Word, but you may be able to achieve this through the use of a background macro. For instance you would need to write a macro that detects when a merge field is inserted and inserts a default image at the same image. This sounds a bit difficult.
Also it may be useful to learn how images are really inserted during mail merge in Microsoft Word. The following site describes this well. You can see that there isn’t really any native support for previewing merged images in Microsoft Word.
When it comes to merging images during processing with Aspose.Words it sounds like you replace the Image_DOUBLEDOT_ImageName with a colon which turns it into a “Image” field recognized by Aspose.Words. This sounds like it will work perfectly fine, please let us know if you are having trouble with this and if so please attach your code and template here for testing.
Therefore I am closing the linked issue opened by Tilal as there is no problem. Please let us know if you have any further clarification.