We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to limit image size in mail merge

Hi there,

I'm doing a nice mail merge with http images. But some of them are huge. Is there any way to limit the size of the images in the merged document?


Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Would you please clarify what you need to achieve? Do you need to limit dimensions of images upon inserting or you need to limit file size of images?

Best regards,

Hi Andrey,

It is more about the dimensions. Sorry because of my bad English :-P


<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. I think you can use DocumentBuilder and FieldMergingCallback to achieve this. For example, please see the following code:

// Open template

Document doc = new Document(@"Test\in.doc");

// Prepare dummy data for mail merge

string[] names = { "myImg" };

object[] values = { File.ReadAllBytes(@"Test\image.jpg") };

// Add merge image field event handler

doc.MailMerge.FieldMergingCallback = new MergeImageFieldResizeImage();

// Execute mail merge

doc.MailMerge.Execute(names, values);

// Save output document


private class MergeImageFieldResizeImage : IFieldMergingCallback


void IFieldMergingCallback.FieldMerging(FieldMergingArgs args)


// Do nothing.


void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs 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);




Best regards,