public void WrapperToAccessLayoutEntities()
        {
            // This sample introduces the RenderedDocument class and other related classes which provide an API wrapper for
            // the LayoutEnumerator. This allows you to access the layout entities of a document using a DOM style API.
            Document doc = new Document(MyDir + "Document layout.docx");

            RenderedDocument layoutDoc = new RenderedDocument(doc);

            // Get access to the line of the first page and print to the console.
            RenderedLine line = layoutDoc.Pages[0].Columns[0].Lines[2];

            Console.WriteLine("Line: " + line.Text);

            // With a rendered line, the original paragraph in the document object model can be returned.
            Paragraph para = line.Paragraph;

            Console.WriteLine("Paragraph text: " + para.Range.Text);

            // Retrieve all the text that appears on the first page in plain text format (including headers and footers).
            string pageText = layoutDoc.Pages[0].Text;

            Console.WriteLine();

            // Loop through each page in the document and print how many lines appear on each page.
            foreach (RenderedPage page in layoutDoc.Pages)
            {
                LayoutCollection <LayoutEntity> lines = page.GetChildEntities(LayoutEntityType.Line, true);
                Console.WriteLine("Page {0} has {1} lines.", page.PageIndex, lines.Count);
            }

            // This method provides a reverse lookup of layout entities for any given node
            // (except runs and nodes in the header and footer).
            Console.WriteLine();
            Console.WriteLine("The lines of the second paragraph:");
            foreach (RenderedLine paragraphLine in layoutDoc.GetLayoutEntitiesOfNode(
                         doc.FirstSection.Body.Paragraphs[1]))
            {
                Console.WriteLine($"\"{paragraphLine.Text.Trim()}\"");
                Console.WriteLine(paragraphLine.Rectangle.ToString());
                Console.WriteLine();
            }
        }
        private LayoutEntity CreateLayoutEntityFromType(LayoutEnumerator it)
        {
            LayoutEntity childEntity;

            switch (it.Type)
            {
            case LayoutEntityType.Cell:
                childEntity = new RenderedCell();
                break;

            case LayoutEntityType.Column:
                childEntity = new RenderedColumn();
                break;

            case LayoutEntityType.Comment:
                childEntity = new RenderedComment();
                break;

            case LayoutEntityType.Endnote:
                childEntity = new RenderedEndnote();
                break;

            case LayoutEntityType.Footnote:
                childEntity = new RenderedFootnote();
                break;

            case LayoutEntityType.HeaderFooter:
                childEntity = new RenderedHeaderFooter();
                break;

            case LayoutEntityType.Line:
                childEntity = new RenderedLine();
                break;

            case LayoutEntityType.NoteSeparator:
                childEntity = new RenderedNoteSeparator();
                break;

            case LayoutEntityType.Page:
                childEntity = new RenderedPage();
                break;

            case LayoutEntityType.Row:
                childEntity = new RenderedRow();
                break;

            case LayoutEntityType.Span:
                childEntity = new RenderedSpan(it.Text);
                break;

            case LayoutEntityType.TextBox:
                childEntity = new RenderedTextBox();
                break;

            default:
                throw new InvalidOperationException("Unknown layout type");
            }

            childEntity.mKind        = it.Kind;
            childEntity.mPageIndex   = it.PageIndex;
            childEntity.mRectangle   = it.Rectangle;
            childEntity.mType        = it.Type;
            childEntity.LayoutObject = it.Current;
            childEntity.mParent      = this;

            return(childEntity);
        }