Free Support Forum - aspose.com

Images not appearing using InsertHTML

Hi,

I simply have HTML as a string, which contains any number of images, each image having an absolute path for the img src.

The problem is that these images do not appear in the Word document generated.

Is there some property I need to set here to get them to appear?

Thanks
Enoch

Hi

Thanks for your request. Images should be imported without any additional properties specified. Please make sure that they are absolute paths. Also could you please attach your HTML with images here for testing? I will check the problem on my side and provide you more information.

Best regards,

Hi Andrey,

I’ve attached the HTML that is passed to the InsertHTML method.

I’ve tried with and tags and without and that didn’t make a difference.

Thanks
Enoch

Hi

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

Thank you for additional information. I cannot reproduce the problem on my side. I used the following code for testing:

string html = File.ReadAllText(@"Test001\InsightTest.html");

DocumentBuilder builder = new DocumentBuilder();

builder.InsertHtml(html);

builder.Document.Save(@"Test001\out.doc");

Do you have internet access in environment where you use Aspose.Words? Also the problem might occur because your firewall blocked access to these images. Try disabling your firewall or testing in other environment.

Best regards,

Hi,

Yes, we have internet access and I very much doubt it’s a firewall issue. The HTML seems fine because running it in a browser works ok.

This is the code we’ve used to generate the Word file:

Dim document As New Aspose.Words.Document()
Dim builder As New Aspose.Words.DocumentBuilder(document)
Dim articleText As String = _newsService.GetNewsByID(newsId) 'This grabs the HTML from database

builder.InsertHtml(articleText)

Dim stream As New System.IO.MemoryStream

document.Save(stream, Aspose.Words.SaveFormat.Doc)

ControllerContext.HttpContext.Response.Clear()
ControllerContext.HttpContext.Response.AddHeader(“cache-control”, “private”)
ControllerContext.HttpContext.Response.AddHeader(“Content-disposition”, “attachment; filename=“myFile.doc”;”)
ControllerContext.HttpContext.Response.AddHeader(“Content-type”, “application/vnd.ms-word”)

stream.WriteTo(ControllerContext.HttpContext.Response.OutputStream)

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

Thank you for additional information. Please try using the following code:

Dim doc As New Document()

Dim html As String = File.ReadAllText("C:\Temp\InsightTest.html")

Dim builder As New DocumentBuilder(doc)

builder.InsertHtml(html)

Dim stream As New MemoryStream()

doc.Save(stream, SaveFormat.Doc)

Response.Clear()

'Specify the document type.

Response.ContentType = "text/plain"

Response.AddHeader("content-disposition", "attachment; filename=MyDocument.doc")

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

Dim bytes As Byte() = stream.GetBuffer()

Response.BinaryWrite(bytes)

Response.[End]()

In case of using this code, the output document looks fine.

Best regards,

Hi Andrey,

I tried this code and still no luck.

We are using Aspose Total version 9.1.0.0

Hi

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

Thank you for additional information. Aspose.Total for .NET includes Aspose.Words. The latest version of Aspose.Words is 9.4.0. Could you please try using the latest version of Aspose.Words and let me know how it goes on your side.

You can download the latest version from here:

http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/category1188.aspx

Best regards,