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.
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.
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 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);
}