Free Support Forum -

Converting html to docx does not include the image?

I want to convert a html file to docx. The html file contains some img elements:

<img id="webImgShrinked" alt="Picture" border="0" galleryimg="false" src="http://wikione/WikiPics/i-builder%20portal/_w/Capture2_JPG.jpg" />

Document word = new Document(stream);

word.SaveOptions.ExportPrettyFormat = true;

word.Save(docxPath, SaveFormat.Docx);

when the docx is created, the image seems to be broken. What should I do?


Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I tried this on my side and all works fine. I used the following HTML.



<img src="http://localhost/TestAsposeWordsImages/myimg.jpg" />



Here is code for converting HTML to DOC.

Document doc = new Document("in.html");

doc.Save("out.docx", SaveFormat.Docx);

This problem can occur because you don’t have permissions to open this link. You can try use the following code for testing.

//You should insert your URI

string url = "http://localhost/TestAsposeWordsImages/myimg.jpg";

//Prepare the web page we will be asking for

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

request.Method = "GET";

request.ContentType = "image/jpeg";

request.UserAgent = "Mozilla/4.0+(compatible;+MSIE+5.01;+Windows+NT+5.0";

//Execute the request

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

//We will read data via the response stream

Stream resStream = response.GetResponseStream();

//Write content into the MemoryStream

BinaryReader resReader = new BinaryReader(resStream);

MemoryStream imgStream = new MemoryStream(resReader.ReadBytes((int)response.ContentLength));

//Create Image

Image img = Image.FromStream(imgStream);

//Save Image


Best regards.

Hello!<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for your interest in Aspose.Words.

Please ensure the referenced image resources are available for the application invoking calls to Aspose.Words. What do you mean under broken images? You can also try reading HTML with local images in the same folder with the file.

Please provide us the HTML and images that become broken for investigation if the experiments above don’t help. You can attach multiple files to one forum post in an archive. ZIP or RAR are preferable but any other is okay too.