Insert pictures into .doc

Last post 08-26-2010, 6:29 AM by aske012. 3 replies.
Sort Posts: Previous Next
  •  08-25-2010, 1:59 PM 255639

    Insert pictures into .doc (Platform: Microsoft Word)

    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:

          <td style="width:529px; background-image: url(img/image.bmp); height: 269px;">

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

    Thanks.
     
  •  08-25-2010, 9:10 PM 255672 in reply to 255639

    Re: Insert pictures into .doc

    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


    Adam Skelton
    Programming Writer
    Aspose Auckland Team
     
  •  08-26-2010, 6:17 AM 255744 in reply to 255672

    Re: Insert pictures into .doc

    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.
     
  •  08-26-2010, 6:29 AM 255748 in reply to 255744

    Re: Insert pictures into .doc

    Hi José,

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

    Thanks,


    Adam Skelton
    Programming Writer
    Aspose Auckland Team
     
View as RSS news feed in XML