RenderedDocument Code Sample Floating Shape Not Allowed Inside Textbox Exception

Hi,

I am getting the following exception when running valid Word documents through the RenderedDocument sample from Github:-

InvalidOperationException - Floating shape not allowed inside textbox.

https://github.com/aspose-words/Aspose.Words-for-.NET

The exception is being generated at the following point in the sample:-

image.png (28.9 KB)

The elements in the Word document (which Word happily supports) are essentially floating text boxes inside text boxes, it doesn’t matter if they are grouped, ungrouped, floating, behind etc. same error is thrown.

AsposeSupportSample1.docx (30.5 KB)

Many thanks in advance

@Neil_Tonkin Aspose.Words also supports shapes like MS Word does in the model. The exception you have encountered is thrown by LayoutEnumerator and this is expected, since shapes are rendered separately from the whole document. So you can get bounds only of the top level shapes using LayoutEnumerator. This is by design.

The mentioned exception can be reproduced with the following simple code with your document:

Document doc = new Document(@"C:\Temp\in.docx");
LayoutEnumerator enumerator = new LayoutEnumerator(doc);
LayoutCollector collector = new LayoutCollector(doc);

Shape textBox = doc.GetChildNodes(NodeType.Shape, true)
    .Cast<Shape>().Where(s => s.ShapeType == ShapeType.TextBox).First();

enumerator.Current = collector.GetEntity(textBox);

Console.WriteLine(enumerator.Rectangle);
1 Like

@alexey.noskov thanks, understood.

1 Like

A post was split to a new topic: Floating shape not allowed inside textbox