Free Support Forum - aspose.com

Resizing MailMerge Images in Document- not changing resolution

This post may be related to these two existing threads, but there was never a resolution.
Image and Merge field
Formatting images in Aspose.Words java MailMerge

I want to resize a mailmerged image without reducing its resolution. In other words, I want the full resolution of the image, but want it to occupy a smaller area on the page. This is so that the image will not appear pixelated when printed.

I believe that the image is inserted at screen resolution (72dpi) by default, but print resolution is somewhere closer to 300dpi. You can do this manually in msword just by dragging the image to resize (resolution isnt decreased, just dimensions on the page)

The previously suggested solutions reduce the actual resolution of the image, which causes it to appear blurry and pixelated when printed.

Is there a solution to this problem?

Hi Justin,


Thanks for your inquiry. I think, you should just specify the width and height (in points) of Image by using DocumentBuilder.InsertImage method. In this case the Image’s actual resolution would be preserved while Microsoft Word still displays the resized image. I have attached a sample document, please try running the following code snippet:

Document doc = new
Document(@“C:\Temp\in.docx”);

doc.MailMerge.FieldMergingCallback = new HandleMergeImageField();

//Execute mail merge

doc.MailMerge.Execute(new string[] { "testField" }, new object[] { @"C:\Temp\Aspose.Words.png"});

//Save output document

doc.Save(@"C:\Temp\out.docx");


private class HandleMergeImageField : IFieldMergingCallback

{

void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)

{

}

public void ImageFieldMerging(ImageFieldMergingArgs args)

{

if (args.FieldName.Equals("testField"))

{

DocumentBuilder builder = new DocumentBuilder(args.Document);

builder.MoveToMergeField(args.FieldName);

builder.InsertImage(args.FieldValue.ToString(), 32, 32);

}

}

}


Moreover, you can find documentation of DocumentBuilder.InsertImage method overloads here:

I hope, this will help.

Best Regards,