DocumentBuilder.InsertHtml does not include referenced images

Hi,

Hi tried this code to insert an html fragment into a word document:

Dim htmlText As String = "The logo is: <img src=""http://www.itconsult.it/style%20library/images/logo_itconsult.jpg"" id=""img1"">"

Dim doc As New Aspose.Words.Document(“source.docx”)
Dim builder As Aspose.Words.DocumentBuilder
builder = New Aspose.Words.DocumentBuilder(doc)

builder.MoveToBookmark(“myBookmark”)

builder.InsertHtml(htmlText)

doc.Save(“dest.docx”, Aspose.Words.SaveFormat.Docx)

But in the destination document the logo image is missing, replaced with a red cross image.

Is there an automatic way to have the linked image inserted into the document?

Thank you for the support.

Hi Alessandro,

Thanks for your inquiry. After an initial test with Aspose.Words for .NET 15.4.0, I was unable to reproduce this issue on my side. I would suggest you please upgrade to the latest version of Aspose.Words. You can download it from the following link. I hope, this helps.
https://releases.aspose.com/words/net

Best regards,

Hi Babar,

I tried again (using the latest version) and I found (maybe) the problem.

I think the problem is the server proxy.

In my environment I have an NTLM proxy server and, if my system administrator disable the proxy (allowing me to navigate without the proxy) the image will be inserted into the docx, otherwise (when the proxy is active) the image will be missed.

Is there a way to set a proxy for the DocumentBuilder object?

Moreover, even if the proxy is disabled, only the internet images (and the local images) will be found. Images on my local network will be missed.

For example, considering this HTML:

Dim htmlText As String = "The logo is now:
<img src=""http://www.itconsult.it/style%20library/images/logo_itconsult.jpg"" id=""img1"">
<img src=""http://josharchive.develop.local/josharchivewebadmin/images/josharchive.png"" id=""img2"">
<img src=""localImage.png"" id=""img3"">
"

the result is:

IMG ID Location Proxy Enabled Proxy Disabled
img1 Internet MISSED OK
img2 Local Intranet MISSED MISSED
img3 Local folder OK OK

Hi, I’ve noticed that the local intranet image was missed because it was on a site with windows authentication.
If the images is on a site (in the local intranet) with anonimous access allowed the image will be loaded.

But this is a little strange because the code was ran with my windows credentials…

Hi,

Thanks for your inquiry. First off, please upgrade to the latest version of Aspose.Words. Secondly, it apparently has to do with some configuration settings of your application, not Aspose.Words. We use the standard approach involving the WebRequest and WebResponse classes to load an image from HTTP. Please try to load the image from your URL using WebRequest and WebResponse and if it fails, you need to review your configuration. Also, if the API cannod load an image from an URL, it should insert a small red cross image. And you can capture such warnings using DocumentBase.WarningCallback Property.

Best regards,

Thank you.
I think that the problem is that, when the Aspose component build the WebRequest it must set the proxy settings. Do you expose that webRequest?
If not, how can I set the proxy for the request?

You tells about a configuration settings of my application… but where I need to configure the proxy, so you can use my configuration?

The WarningCallback property allow me to know that an image was not found but I cannot do anything…

Please see my attached project.

Thank you.

Hi,

Thanks for your inquiry. We are working over your query and will get back to you soon.

Best regards,

Hi Alessandro,

Thanks for being patient. You can use Document.ResourceLoadingCallback to load the images from behind the proxy. Here is sample code:

internal class UserProvidedDataHandler : IResourceLoadingCallback
{
    public ResourceLoadingAction ResourceLoading(ResourceLoadingArgs args)
    {
        if (args.ResourceType == ResourceType.Image)
        {
            Assert.IsNotEmpty(args.OriginalUri);
            // Set test data.
            args.SetData(new byte[5]);
            return ResourceLoadingAction.UserProvided;
        }
        return ResourceLoadingAction.Default;
    }
}

I hope, this helps.

Best regards,

Thanks a lot!
This solves my problem!

Best regards.