Free Support Forum - aspose.com

Converting HTML to DOCX. Embed Images

The below code does not select and images from my html. example of html at bottom.
I have also tried selecting fields of HyperlinkField and still no success.
please assist. I need to embed images from

foreach (Shape s in doc.GetChildNodes(NodeType.Shape, true))
        {
            string src = s.ImageData.SourceFullName;
            if (!src.Equals(string.Empty))
            {
                string extention = src.ToLower().Substring(src.Length - 3);
                if (imageExtentions.Contains(extention))
                {
                    builder.InsertImage(src);
                }
            }
        }

< img src=“https://cdn.pixabay.com/photo/2014/06/03/19/38/road-sign-361514_960_720.png” />

@rileyja,

Thanks for your inquiry. The IMG tag is imported into Aspose.Words’ DOM as Shape node. You can get the image data using Shape.ImageData property. This property provides access to the image of the shape. In your case, there is no need to use ImageData.SourceFullName property. This property is used for linked OLE objects.

If you want to get the image’s URI, please implement the IResourceLoadingCallback as shown below. Please implement this interface if you want to control how Aspose.Words loads external resource when importing a document from HTML or MHTML.

public class HandleResourceLoading : IResourceLoadingCallback
{
    public ResourceLoadingAction ResourceLoading(ResourceLoadingArgs args)
    {
        String url = args.OriginalUri;
          
        return ResourceLoadingAction.Default;
    }
}

Aspose.Words.LoadOptions options = new Aspose.Words.LoadOptions();
options.ResourceLoadingCallback = new HandleResourceLoading();
Document doc = new Document(MyDir + @"in.html", options);

Could you please share some more detail about your query along with input HTML and expected output document? We will then provide you more information about your query along with code.