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

Free Support Forum - aspose.com

Docx to HTML with linked images conversion. How to prevent internet access during conversion?

I am using Aspose.Words.Document class to convert docx files to html.
In the docx file there is a single image which was added using Insert->Picture with ‘Link to file’ with a web reference to an image, instead of the ‘insert’ with a image.

This causes the image to be added a url reference in the final emitted html file.

The issue is, when this happens, aspose calls out to the web with the URL of every embedded image. This causes exceptions as the machine where the processing is occurring doesn’t have internet access. Yet, the html is generated correctly.

Does anyone know how to prevent this behavior?
Why does this even happen? The image URL is a link in the docx and an href in the html, it’s address appears to be simply copied from one to another.
And it works, even when it can’t access the image, hence I don’t even understand why it is trying to access the web.

Thanks, any help appreciated .

Hi Guy,

Thanks for your inquiry. A class implementing IResourceLoadingCallback interface can be used to control how resources such as images or CSS are handled when they need to be downloaded from an external source i.e a network or internet. Please see the following example which bans all network resources from loading:

Aspose.Words.LoadOptions loadOptions = new Aspose.Words.LoadOptions();
loadOptions.LoadFormat = LoadFormat.Docx;
loadOptions.ResourceLoadingCallback = new HandleResourceLoading();
Document doc = new Document(@"C:\Temp\in.docx", loadOptions);
public class HandleResourceLoading : IResourceLoadingCallback
    public ResourceLoadingAction ResourceLoading(ResourceLoadingArgs args)
        return ResourceLoadingAction.Skip;

I hope, this helps.

Best regards,

Hi Awais,
Great! That is exactly what I needed and it worked perfectly