Free Support Forum - aspose.com

Problem with images when converting html to doc

I have a html page with some image tags like the following,



When I convert it to a word doc, the images are not saved into the doc. I know I can save the images to files and modify the image tags to reference them. But I’d like to know if there is a simpler solution.

Thanks,
-Bin

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.

<html>

<body>

<img src="http://localhost/TestAsposeWordsImages/Images.aspx?id=1" />

</body>

</html>

Here is code for converting HTML to DOC.

Document doc = new Document(@"Test090\in.html");

doc.Save(@"Test090\out.doc");

And here is code of Image.aspx page.

protected void Page_Load(object sender, EventArgs e)

{

if (Request.Params["id"] != null)

{

Response.Clear();

//Specify the document type.

Response.ContentType = "image/jpeg";

//Specify how the document is sent to the browser.

Response.AddHeader("content-disposition", "inline; filename=test.jpg");

//Get data bytes from the stream and send it to the response.

byte[] bytes = System.IO.File.ReadAllBytes(Server.MapPath("test.jpg"));

Response.BinaryWrite(bytes);

Response.End();

}

}

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/Images.aspx?id=1";

//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

img.Save(@"Test090\out.jpg");

Best regards.

I think it is an authentication issue. I tried my image link in Firefox and I was prompted to enter a user name and password. However, Internet Exploer automatically sent the username/password. Is there a way to support Windows integrated authenitcation when retriving links embeded in html doc?

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

Thank you for your clarification.

If you were asked for credentials this is definetly an access issue. Aspose.Words doesn’t support Windows integrated authentication. As a workaround you can first retrieve the images with tools that are aware of securify and able to do so. That’s what you suggested in the first post.

Please let us know if this works in your case.

Regards,