Free Support Forum - aspose.com

Image Compression

Hi Aspose,


I have a desktop application, built with C#.
Basically this application will read the word files, and generate the html files.

Some word documents have images, and the image is too big for web page.

Is it possible if I use aspose to detect if a content is an image, and when its images, the application will compress the image to websage image.

Cheers

Hi Arthur,


Thanks for your inquiry. Please find attached a sample project. Also, please check HtmlSaveOptions.ImageSavingCallback property. I hope, this helps.

Best regards,

Hi Awais,


Thank you for the sample code. It was very helpful.

Starting from last week, I’m getting exception when compressing the image in my doc.
I’ve put a try catch block to eliminate the exception, this is because although there is an exception,
the codes did manage to generate a doc with compressed image.

But it will be great if the exception is not there, because I’m using this codes in generarting millions of documents.

The exception is:
Object reference not set to an instance of an object on the shape object.

DrawingML shape = (DrawingML)doc.GetChild(NodeType.DrawingML, 0, true);


Attached is the screenshot of the exception.

I hope you can help me to solve this.

Cheers

Hi Arthur,


Thanks for your inquiry. DrawingML class is no longer available in latest versions of Aspose.Words. I have removed all occurrences of this class from code. Please see attached new code. I hope, this helps.

Best regards,

Awesome, thanks Awais.