GetChildNodes is not giving proper order

Hi,

When i’m using the below code i’m not getting the proper order of the shape.

foreach (Aspose.Words.Drawing.Shape img in doc.GetChildNodes(NodeType.Shape, true))
{
string myAltText=img.AlternativeText;
}

i’m got getting execpted output.
EG:
In my word document i have
5 Shapes one by one with AltText as:
Shape One
Shape Two
Shape Three
Shape Four
Shape Five

Loops bring in diffrent order
Shape Five
Shape Four
Shape Two
Shape Three
Shape One

How to get the items in proper order as it is in document.

please help on this.

Thanks
Maran.K
TestingFile.pdf (81.4 KB)

@kasima1

Thanks for your inquiry. Please ZIP and attach your input Word document here for testing. We will investigate the issue on our side and provide you more information.

TestingFile.zip (21.8 KB)

Please find the attachment.

@kasima1

Thanks for sharing the document. We are investigating this issue and will answer you shortly.

@kasima1

You are facing the expected behavior of Aspose.Words. Please unzip the DOCX and check the document.xml. You will notice that the shape with alternative text <<Five>> is appeared first. You can also check this behavior in MS Word. Select all images and set their wrap type as “Inline”. Please check the attached image for detail.

Thanks tahir,

Based on your input, I can understand how the functionality works on word, but how we can explain the same when user upload the file with images.

When user upload a file they expect first image should come at first, and so on.

But I’m not able to bring the order because it words based on Inline format.

Please provider solution to get the proper order of the images.

@kasima1,

Thanks for your inquiry. The Aspose.Words.Layout namespace provides classes that allow to access information such as on what page and where on a page particular document elements are positioned, when the document is formatted into pages.

In your case, we suggest you please use the layout API to get the position of shape so that you can determine what is the shape’s appearance in the document’s page. Following code example shows how to get the left top position of shape.

var doc = new Document(MyDir + "TestingFile.docx");
LayoutCollector collector = new LayoutCollector(doc);
LayoutEnumerator enumerator = new LayoutEnumerator(doc);

foreach (Shape shape in doc.GetChildNodes(NodeType.Shape, true))
{
    enumerator.Current = collector.GetEntity(shape);
    Console.Write("Page number : " + collector.GetStartPageIndex(shape) + " Top : " + enumerator.Rectangle.Top + " Left : " + enumerator.Rectangle.Left);
    Console.WriteLine(shape.AlternativeText);
}
1 Like