Change DPI of all pictures befor saving to *.doc or *.docx

Hi, I can ask if is possible change DPI or resolution of all images in document befor saving in *.doc or *.docx format. I use Aspose.Word.

Thanks a lot. Michal

Hello.


Thanks for your request. Aspose.Words does not allow you to do this directly, but you can use the following workaround.
1. Get objects that contain images.
2. Convert these objects to Bitmap and change the resolution.
3. Save Bitmap to the original object.
Please see the code below.

string filename = @“in.doc”;

Document doc = new Document(filename);


//DrawingML

foreach (ImageData item in doc.GetChildNodes(NodeType.DrawingML, true))

{

Bitmap image = (Bitmap)item.ToImage();

image.SetResolution(20, 20);

item.SetImage((Image)image);

}


//Shape

foreach (Shape item in doc.GetChildNodes(NodeType.Shape, true))

{

Bitmap image = (Bitmap)item.ImageData.ToImage();

image.SetResolution(20, 20);

item.ImageData.SetImage((Image)image);

}


doc.Save(“out.doc”);

Best regards,