public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_RenderingAndPrinting();

            string   fileName = "TestFile.docx";
            Document doc      = new Document(dataDir + fileName);

            // 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.

            // Create a new RenderedDocument class from a Document object.
            RenderedDocument layoutDoc = new RenderedDocument(doc);

            // The following examples demonstrate how to use the wrapper API.
            // This snippet returns the third line of the first page and prints the line of text 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 of 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 (with the exception of 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(string.Format("\"{0}\"", paragraphLine.Text.Trim()));
                Console.WriteLine(paragraphLine.Rectangle.ToString());
                Console.WriteLine();
            }

            Console.WriteLine("\nDocument layout helper example ran successfully.");
        }
        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);
        }