Aspose Words equivalent to "Compress Pictures" functionality in Word

Hello Aspose support team,

we cannot find the Aspose equivalent to the “Compress Pictures” function in Word.

When clicking the Compress Pictures button in the ribbon, a dialog opens, where the user is able to set the desired resolution for the compressed images:

We would need this functionality in Aspose Words too. If it is not yet implemented, is there a chance that it will be added in a future release?

Thank you and keep up your great work,
Stefanie

@stefanie.huber I am afraid there is no such built in feature in Aspose.Words. However, you can achieve this on your side using code like the following:

Document doc = new Document(@"C:\Temp\in.docx");
// Get shapes with images from the document.
List<Shape> imageShapes = doc.GetChildNodes(NodeType.Shape, true).Cast<Shape>()
    .Where(s => s.HasImage).ToList();
// Loop theough the image shapes
foreach (Shape s in imageShapes)
{
    // Get the iriginal image bytes.
    byte[] imageBytes = s.ImageData.ImageBytes;

    // process the image as it is rrequired.
    // .................

    s.ImageData.ImageBytes = processedImageBytes;
}
// Save the output.
doc.Save(@"C:\Temp\out.docx");

The approach is pretty simple - get the shape with images from the document, process the image (compress, resize etc) and then set the processed image bytes back.

Hi Aleyey,

thank you very much for your reply. We will use your workaround to solve our problem.

Many thanks and best regards,
Stefanie

1 Like