Modify the Image Dimensions

We use mailmerge to get the BLOB from database and convert to image. How do we change the dimensions (Width and Height) of the image in Aspose after mailmerging.


Thanks for your inquiry. I think you can use DocumentBuilder and MergeImageField event handler to achieve this. For example, please see the following code:

// Open template
Document doc = new Document(@"Test200\in.doc");
// Prepare dummy data for mail merge
string[] names = {
object[] values = {
// Add merge image field event handler
doc.MailMerge.MergeImageField += new MergeImageFieldEventHandler(MergeImageField_ResizeImage);
// Execute mail merge
doc.MailMerge.Execute(names, values);
// Save output document
void MergeImageField_ResizeImage(object sender, MergeImageFieldEventArgs e)
    // Create DocuemntBuilder and move its cursor to the mergefield
    DocumentBuilder builder = new DocumentBuilder(e.Document);
    builder.MoveToField(e.Field, true);
    // Insert image and specify its size
    builder.InsertImage((byte[]) e.FieldValue, 100, 100);

Hope this helps.
Best regards.