HTML to DOCX and image handling

So I saw elsewhere on the site how easy it is to load an HTML file and then save it as DOCX (literally 2 lines of code, it seems). But how are image references handled? I’d like the image references in the HTML file to be invoked during the conversion, with the image being included directly in the DOCX file – that way the final product is self-contained and doesn’t need network access to properly view/edit the file. I know this can be done in MS Word U/I with a just a few clicks, but I was wondering how it would be handled programmatically in ASPOSE.

Hi Garth,


Thanks for your inquiry. Please note that Aspose.Words automatically downloads the image before inserting into the document if you specify a remote URL in src attribute of in Html. Therefore, the output DOCX document contains the image in it and you don’t need network access to view the image in DOCX. Please let me know if I can be of any further assistance.

Best regards,

Hi Team,

Is there any call back while converting html to word where we can handle images that have custom url in img source (in html) .My requirement is to load these images and put them in html before converting them to word.

@ashu_agrawal_sirionlabs_com Sure, you can use IResourceLoadingCallback to handle external resources loading.

Thanks for the reply.

Can you please guide me the code if I am using document builder approach.

Using documentBuilder.insertHtml('");

@ashu_agrawal_sirionlabs_com Unfortunately, there is no way to pass IResourceLoadingCallback into DocumentBuilder.insertHtml. I can only suggest to load HTML into a separate document and then use DocumentBuilder.insertDocument. In this case upon loading document you can use IResourceLoadingCallback.