Critical Image issue in Aspose.Words - word to html conversion- unable to detect diagram-shapes- and other image type

I want to iterate through every image type (diagrams, custom shapes, images) line by line in word document(.docx) and upload the image type to cloud and pass the image url to src tag of converted html file.

I used two loop to iterate through images and custom shape.

Loop 1 :

Document newDoc = new Document(sourceDocumentFileName);

List<string> imgUris = new List<string>();
foreach (DrawingML s in newDoc.GetChildNodes(NodeType.DrawingML, true))
{
    if (s.HasImage)
    {
        // upload the image to cloud server and retrieve new url
        string imgUrl = UploadImageToServer(s);
        imgUris.Add(imgUrl);
        string imgName = Path.GetFileName(imgUrl);
        s.AlternativeText = imgName;
    }

}

Loop 2 :

foreach (Shape st in newDoc.GetChildNodes(NodeType.Shape, true))
{
    if (st.HasImage)
    {
        // upload the image to cloud and retrieve new url        
        string imgURL = string.Empty;
        string imageFileName = Server.MapPath("~/Documents/" + Guid.NewGuid().ToString("N") + st.Name + "." + st.ImageData.ImageType);

        st.ImageData.Save(imageFileName);
        CloudBlockBlob blockBlobSOPDocImage = Azure.UploadToBlob(Path.GetFileName(imageFileName), imageFileName, strBlobContainer);
        if (System.IO.File.Exists(imageFileName))
        {
            System.IO.File.Delete(imageFileName);
        }
        string imgUrl = blockBlobSOPDocImage.Uri.ToString();
        imgUris.Add(imgUrl);
        string imgName = Path.GetFileName(imgUrl);
        st.AlternativeText = imgName;
    }
}

My query is that, is there any way to loop through entire document and find the image type line by line and upload image to cloud respectively.

Q.1 : Can this be done using single loop ? and How ?

Q.2 : Is there any way to identify and save custom shape to cloud, as custom shapes has no image type extension, tried hard coding the image extension but of no use,

I bought the license but unable to meet the requirement via Aspose.Words,

I am afraid, If Aspose can solve this issue !

Attached a sample document.

Hi there,

Thanks for your inquiry.

*hcm440:

Q.1 : Can this be done using single loop ? and How ?*

You are correctly getting the images using DrawingML and Shape nodes. Images
in Word documents are either represented by Shape nodes or by DrawingML nodes when loading into Aspose.Words’ DOM.The image found in your document is actually represented by DrawingML node.

Please read the members of DrawingML and Shape class from here:
https://reference.aspose.com/words/net/aspose.words.drawing/shape/
https://reference.aspose.com/words/net/aspose.words.drawing/shape/

*hcm440:

Q.2 : Is there any
way to identify and save custom shape to cloud, as custom shapes has no
image type extension, tried hard coding the image extension but of no
use,*

In your case, I suggest you please convert the shape node to image as shown below. Hope this helps you.

If you still face problem, please attach your input Word document which contains the custom shapes here for testing. I will investigate the issue on my side and provide you more information.

Document doc = new Document(MyDir + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
foreach(Shape shape in shapes.ToArray())
{
    MemoryStream stream = new MemoryStream();
    shape.GetShapeRenderer().Save(stream, new ImageSaveOptions(SaveFormat.Png));
    builder.MoveTo(shape);
    Shape newShape = builder.InsertImage(stream, shape.Width, shape.Height);
    newShape.HRef = "http://www.aspose.com/images/aspose-logo.gif";
    shape.Remove();
}
doc.Save(MyDir + "Out.html");

Moved here: Critical Image issue in Aspose.Words - word to html conversion- unable to detect diagram-shapes- and other image type - Free Support Forum - aspose.com