Sign UpSign Up   Sign InSign In Welcome Guest,
Live Chat Live Chat

Aspose.Words does not show the images when we insert html containing img tag with relative url.

Last post 03-03-2009, 3:37 AM by viplav. 3 replies.
Sort Posts: Previous Next
  •  02-23-2009, 3:36 AM 166385

    Aspose.Words does not show the images when we insert html containing img tag with relative url.

    Hi I am evaluating Aspose.Words for using it to generate word doc from html. I am using following code:
     

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

            builder.InsertHtml(

                "<P align='right'>Xyz</P>" +

                "<b>123</b>" +

                "<div align='center'>ABC</div>" +

                "<h1 align='left'>Heading 1 left.</h1> <img src='images/logo_main.gif'/>");
            doc.Save("Test.docx", SaveFormat.Docx, SaveType.OpenInWord, Response);
            Response.End();

    In my Page Test.aspx(Test.aspx.cs). The path of image is just relative to Test.aspx.

    The generated document does not show the image. I know that it is a problem of Image path. Aspose.Words is not able to get the right image path. If  I provide the
    "<img src='"+Server.MapPath("images/logo_main.gif")+"'/> " , it works or I provide it as
    <img src='localhost://images/logo_main.gif'/>, also works. But I can not do these because our preexisting documents have relative url. My suggestion is that you people can provide a property to set the context path for the document, so that Aspose.words can map the path automatically.

    -Sushil

    This message was posted using Page2Forum from Aspose.Total for .NET and Java - Documentation
     
  •  02-23-2009, 6:08 AM 166399 in reply to 166385

    Re: Aspose.Words does not show the images when we insert html containing img tag with relative url.

    Hi

     

    Thanks for your request. I created new issue #7620 in our defect database regarding this problem. I will notify you as soon as it is fixed.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  02-23-2009, 4:04 PM 166540 in reply to 166399

    Re: Aspose.Words does not show the images when we insert html containing img tag with relative url.

    Hello Sushil!

     

    Thank you for your interesting question. We’ll think about how to parameterize the base URI to affect InsertHtml. But I probably can suggest workarounds for you. Since the documents are being constructed with InsertHtml calls you can prepend every HTML snippet with the following string:

     

    string baseUriDeclaration = “<base href=’” + Server.MapPath(“.”) + “’/>”;

    builder.InsertHtml(baseUriDeclaration + someHtmlSnippet);

    ...

     

    In case if you load a complete document from a stream you can specify base URI in the Document constructor directly:

    http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/aspose.words.documentconstructor6.html

     

    Please let me know if this helps solve your task.

     

    Regards,
    Viktor Sazhaev
    Software Engineer, Aspose Auckland Team
     
  •  03-03-2009, 3:37 AM 167831 in reply to 166540

    Re: Aspose.Words does not show the images when we insert html containing img tag with relative url.

    Hi Klepus,
    Thanks for your response. This helped me to fix the problem. I will recommend to my company to use Aspose.Words. Though I can write word documents by using Microsoft SDK for Office OpenXml Format, yet I liked the insertion of html in to word doc and converts it to WordML.

    Thanks Again.

    -Sushil
     
View as RSS news feed in XML