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

Free Support Forum - aspose.com

Insert pictures into .doc

Hello,

I need to export html pages to Doc. I’ve studying some libraries, how: Syncfusion, Microsoft.Office.Interop.Word, etc… After all tests, the Aspose library was where I got the most satisfactory result.

I do the insertion of html text directly using the method InsertHtml of the DocumentBuilder. But the images in the html document is not being sent to the document .doc created.

Sample code:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(HttpContext.Current.Request.Url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();

request.Method = “GET”;
request.ContentType = “application/msword”;
request.UserAgent = “Mozilla/4.0+(compatible;+MSIE+5.01;+Windows+NT+5.0”;

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

StreamReader reader = new StreamReader(imgStream);
string text = reader.ReadToEnd();

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.InsertHtml(text);

doc.Save(“example.doc”, SaveFormat.Doc, SaveType.OpenInApplication, Response);

The images aren’t retrieved and sent to the created document.

Below is an example of the use of images:



I count on the assistance of everyone to continue using the library.

Thanks.

Hi there,

Thanks for your request. I'm afraid the background-image attribute is generally unsupported when importing to Word documents. This is because HTML and document formats are very different. Some features that are available in HTML are not available in MS Word and vice versa.

In this case, HTML allows specifying an image as a background of table cell, but in MS Word there is no such feature. Please note that even MS Word does not import background image of table cell from HTML.

Instead you might want to look into setting an img tag inside the cell and remove any padding from the cell instead. This should be imported properly when inserting the HTML into your document.

If you have any further queries, please feel free to ask.

Thanks

Thanks Adam,

Imagine it was something related to the formatting of html.

I Decided to use templates, is a bit more work but serves the purpose. I will present the library to the project manager for release to use.

Thank you for listening and congratulate you on excellent library.

Hi José,

Thanks for that. Please feel free to ask for help if you have any further queries.

Thanks,