static void Main(string[] args)
        {
            ApplyLicense();

            Document doc = new Document("eSignature.Test.02.docx");

            //Find the text between <<>> and insert bookmark
            doc.Range.Replace(new Regex(@"\<<.*?\>>"), "", new FindReplaceOptions()
            {
                ReplacingCallback = new FindAndInsertBookmark()
            });

            LayoutCollector  layoutCollector  = new LayoutCollector(doc);
            LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);

            //Display the left top position of text between angle bracket.
            foreach (Bookmark bookmark in doc.Range.Bookmarks)
            {
                if (bookmark.Name.StartsWith("bookmark_"))
                {
                    layoutEnumerator.Current = layoutCollector.GetEntity(bookmark.BookmarkStart);
                    Console.WriteLine(" --> Left : " + layoutEnumerator.Rectangle.Left + " Top : " + layoutEnumerator.Rectangle.Top);
                }
            }
            doc.Save("20.10.docx");

            System.Diagnostics.Process.Start("20.10.docx");
        }
        /// <summary>
        /// Adds a colored border around each layout element on the page.
        /// </summary>
        private static void AddBoundingBoxToElementsOnPage(LayoutEnumerator layoutEnumerator, Graphics g)
        {
            do
            {
                // Use MoveLastChild and MovePrevious to enumerate from last to the first enumeration is done backward,
                // so the lines of child entities are drawn first and don't overlap the parent's lines.
                if (layoutEnumerator.MoveLastChild())
                {
                    AddBoundingBoxToElementsOnPage(layoutEnumerator, g);
                    layoutEnumerator.MoveParent();
                }

                // Convert the rectangle representing the position of the layout entity on the page from points to pixels.
                RectangleF rectF = layoutEnumerator.Rectangle;
                Rectangle  rect  = new Rectangle(PointToPixel(rectF.Left, g.DpiX), PointToPixel(rectF.Top, g.DpiY),
                                                 PointToPixel(rectF.Width, g.DpiX), PointToPixel(rectF.Height, g.DpiY));

                // Draw a line around the layout entity on the page.
                g.DrawRectangle(GetColoredPenFromType(layoutEnumerator.Type), rect);

                // Stop after all elements on the page have been processed.
                if (layoutEnumerator.Type == LayoutEntityType.Page)
                {
                    return;
                }
            } while (layoutEnumerator.MovePrevious());
        }
        public bool IsSameLayout(SceneLayoutData other)
        {
            if (LayoutId != other.LayoutId)
            {
                return(false);
            }
            if (lightingId != other.lightingId || musicTrackId != other.musicTrackId)
            {
                return(false);
            }
            if (layout.Count != other.layout.Count)
            {
                return(false);
            }
            LayoutEnumerator layoutEnumerator = GetLayoutEnumerator();

            foreach (DecorationLayoutData item in layoutEnumerator)
            {
                ParentedSet <string, DecorationLayoutData> parentedSet = other.layout;
                DecorationLayoutData.ID id = item.Id;
                if (!parentedSet.ContainsKey(id.GetFullPath()))
                {
                    return(false);
                }
                ParentedSet <string, DecorationLayoutData> parentedSet2 = other.layout;
                id = item.Id;
                DecorationLayoutData other2 = parentedSet2.Get(id.GetFullPath());
                if (!item.Equals(other2))
                {
                    return(false);
                }
            }
            return(true);
        }
        /// <summary>
        /// Adds a colored border around each layout element on the page.
        /// </summary>
        private static void AddBoundingBoxToElementsOnPage(LayoutEnumerator it, Graphics g)
        {
            do
            {
                // This time instead of MoveFirstChild and MoveNext, we use MoveLastChild and MovePrevious to enumerate from last to first.
                // Enumeration is done backward so the lines of child entities are drawn first and don't overlap the lines of the parent.
                if (it.MoveLastChild())
                {
                    AddBoundingBoxToElementsOnPage(it, g);
                    it.MoveParent();
                }

                // Convert the rectangle representing the position of the layout entity on the page from points to pixels.
                RectangleF rectF = it.Rectangle;
                Rectangle rect = new Rectangle(PointToPixel(rectF.Left, g.DpiX), PointToPixel(rectF.Top, g.DpiY),
                    PointToPixel(rectF.Width, g.DpiX), PointToPixel(rectF.Height, g.DpiY));

                // Draw a line around the layout entity on the page.
                g.DrawRectangle(GetColoredPenFromType(it.Type), rect);

                // Stop after all elements on the page have been procesed.
                if (it.Type == LayoutEntityType.Page)
                    return;

            } while (it.MovePrevious());
        }
 /// <summary>
 /// Creates a new instance from the supplied Document class.
 /// </summary>
 /// <param name="document">A document whose page layout model to enumerate.</param>
 /// <remarks><para>If page layout model of the document hasn't been built the enumerator calls <see cref="Document.UpdatePageLayout"/> to build it.</para>
 /// <para>Whenever document is updated and new page layout model is created, a new RenderedDocument instance must be used to access the changes.</para></remarks>
 public RenderedDocument(Document doc)
 {
     mLayoutCollector = new LayoutCollector(doc);
     mEnumerator      = new LayoutEnumerator(doc);
     ProcessLayoutElements(this);
     LinkLayoutMarkersToNodes(doc);
     CollectLinesAndAddToMarkers();
 }
        /// <summary>
        /// Reserved for internal use.
        /// </summary>
        internal LayoutEntity AddChildEntity(LayoutEnumerator it)
        {
            LayoutEntity child = CreateLayoutEntityFromType(it);

            mChildEntities.Add(child);

            return(child);
        }
 /// <summary>
 /// Creates a new instance from the supplied Aspose.Words.Document class.
 /// </summary>
 /// <param name="document">A document whose page layout model to enumerate.</param>
 /// <remarks><para>If page layout model of the document hasn't been built the enumerator calls <see cref="Document.UpdatePageLayout"/> to build it.</para>
 /// <para>Whenever document is updated and new page layout model is created, a new RenderedDocument instance must be used to access the changes.</para></remarks>
 public RenderedDocument(Document doc)
 {
     mLayoutCollector = new LayoutCollector(doc);
     mEnumerator = new LayoutEnumerator(doc);
     ProcessLayoutElements(this);
     LinkLayoutMarkersToNodes(doc);
     CollectLinesAndAddToMarkers();
 }
        /// <summary>
        /// Displays information about the current layout entity to the console.
        /// </summary>
        private static void DisplayEntityInfo(LayoutEnumerator it, string padding)
        {
            Console.Write(padding + it.Type + " - " + it.Kind);

            if (it.Type == LayoutEntityType.Span)
                Console.Write(" - " + it.Text);

            Console.WriteLine();
        }
        /// <summary>
        /// Displays information about the current layout entity to the console.
        /// </summary>
        private static void DisplayEntityInfo(LayoutEnumerator layoutEnumerator, string padding)
        {
            Console.Write(padding + layoutEnumerator.Type + " - " + layoutEnumerator.Kind);

            if (layoutEnumerator.Type == LayoutEntityType.Span)
            {
                Console.Write(" - " + layoutEnumerator.Text);
            }

            Console.WriteLine();
        }
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Logical" order.
        /// </summary>
        private static void TraverseLayoutForwardLogical(LayoutEnumerator layoutEnumerator, int depth)
        {
            do
            {
                PrintCurrentEntity(layoutEnumerator, depth);

                if (layoutEnumerator.MoveFirstChild())
                {
                    TraverseLayoutForwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.MoveParent();
                }
            } while (layoutEnumerator.MoveNextLogical());
        }
        public void GetLayoutElements()
        {
            Document doc = new Document(MyDir + "Document layout.docx");

            // Enumerator which is used to "walk" the elements of a rendered document.
            LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);

            // Use the enumerator to write information about each layout element to the console.
            LayoutInfoWriter.Run(layoutEnumerator);

            // Adds a border around each layout element and saves each page as a JPEG image to the data directory.
            OutlineLayoutEntitiesRenderer.Run(doc, layoutEnumerator, ArtifactsDir);
        }
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Logical" order.
        /// </summary>
        private static void TraverseLayoutBackwardLogical(LayoutEnumerator layoutEnumerator, int depth)
        {
            do
            {
                PrintCurrentEntity(layoutEnumerator, depth);

                if (layoutEnumerator.MoveLastChild())
                {
                    TraverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.MoveParent();
                }
            } while (layoutEnumerator.MovePreviousLogical());
        }
        /// <summary>
        /// Enumerates forward through each layout element in the document and prints out details of each element. 
        /// </summary>
        private static void DisplayLayoutElements(LayoutEnumerator it, string padding)
        {
            do
            {
                DisplayEntityInfo(it, padding);

                if (it.MoveFirstChild())
                {
                    // Recurse into this child element.
                    DisplayLayoutElements(it, AddPadding(padding));
                    it.MoveParent();
                }
            } while (it.MoveNext());
        }
        /// <summary>
        /// Enumerates forward through each layout element in the document and prints out details of each element.
        /// </summary>
        private static void DisplayLayoutElements(LayoutEnumerator layoutEnumerator, string padding)
        {
            do
            {
                DisplayEntityInfo(layoutEnumerator, padding);

                if (layoutEnumerator.MoveFirstChild())
                {
                    // Recurse into this child element.
                    DisplayLayoutElements(layoutEnumerator, AddPadding(padding));
                    layoutEnumerator.MoveParent();
                }
            } while (layoutEnumerator.MoveNext());
        }
Example #15
0
        public static void Main()
        {
            string dataDir = Path.GetFullPath("../../../Data/");

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

            // This creates an enumerator which is used to "walk" the elements of a rendered document.
            LayoutEnumerator it = new LayoutEnumerator(doc);

            // This sample uses the enumerator to write information about each layout element to the console.
            LayoutInfoWriter.Run(it);

            // This sample adds a border around each layout element and saves each page as a JPEG image to the data directory.
            OutlineLayoutEntitiesRenderer.Run(doc, it, dataDir);
        }
Example #16
0
        public static void Main()
        {
            string dataDir = Path.GetFullPath("../../../Data/");

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

            // This creates an enumerator which is used to "walk" the elements of a rendered document.
            LayoutEnumerator it = new LayoutEnumerator(doc);

            // This sample uses the enumerator to write information about each layout element to the console.
            LayoutInfoWriter.Run(it);

            // This sample adds a border around each layout element and saves each page as a JPEG image to the data directory.
            OutlineLayoutEntitiesRenderer.Run(doc, it, dataDir);
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_RenderingAndPrinting();

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

            // This creates an enumerator which is used to "walk" the elements of a rendered document.
            LayoutEnumerator it = new LayoutEnumerator(doc);

            // This sample uses the enumerator to write information about each layout element to the console.
            LayoutInfoWriter.Run(it);

            // This sample adds a border around each layout element and saves each page as a JPEG image to the data directory.
            OutlineLayoutEntitiesRenderer.Run(doc, it, dataDir);

            Console.WriteLine("\nEnumerate layout elements example ran successfully.");
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_RenderingAndPrinting(); 

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

            // This creates an enumerator which is used to "walk" the elements of a rendered document.
            LayoutEnumerator it = new LayoutEnumerator(doc);

            // This sample uses the enumerator to write information about each layout element to the console.
            LayoutInfoWriter.Run(it);

            // This sample adds a border around each layout element and saves each page as a JPEG image to the data directory.
            OutlineLayoutEntitiesRenderer.Run(doc, it, dataDir);

            Console.WriteLine("\nEnumerate layout elements example ran successfully.");
        }
        /// <summary>
        /// Print information about layoutEnumerator's current entity to the console, indented by a number of tab characters specified by indent.
        /// The rectangle that we process at the end represents the area and location thereof that the element takes up in the document.
        /// </summary>
        private static void PrintCurrentEntity(LayoutEnumerator layoutEnumerator, int indent)
        {
            string tabs = new string('\t', indent);

            Console.WriteLine(layoutEnumerator.Kind == string.Empty
                ? $"{tabs}-> Entity type: {layoutEnumerator.Type}"
                : $"{tabs}-> Entity type & kind: {layoutEnumerator.Type}, {layoutEnumerator.Kind}");

            // Only spans can contain text
            if (layoutEnumerator.Type == LayoutEntityType.Span)
            {
                Console.WriteLine($"{tabs}   Span contents: \"{layoutEnumerator.Text}\"");
            }

            RectangleF leRect = layoutEnumerator.Rectangle;

            Console.WriteLine($"{tabs}   Rectangle dimensions {leRect.Width}x{leRect.Height}, X={leRect.X} Y={leRect.Y}");
            Console.WriteLine($"{tabs}   Page {layoutEnumerator.PageIndex}");
        }
Example #20
0
        [Test] //ExSkip
        public void LayoutEnumerator()
        {
            // Open a document that contains a variety of layout entities.
            // Layout entities are pages, cells, rows, lines and other objects included in the LayoutEntityType enum.
            // Each layout entity has a rectangular space that it occupies in the document body.
            Document doc = new Document(MyDir + "Layout entities.docx");

            // Create an enumerator that can traverse these entities like a tree.
            LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);

            Assert.AreEqual(doc, layoutEnumerator.Document);

            layoutEnumerator.MoveParent(LayoutEntityType.Page);

            Assert.AreEqual(LayoutEntityType.Page, layoutEnumerator.Type);
            Assert.Throws <InvalidOperationException>(() => Console.WriteLine(layoutEnumerator.Text));

            // We can call this method to make sure that the enumerator will be at the first layout entity.
            layoutEnumerator.Reset();

            // There are two orders that determine how the layout enumerator continues traversing layout entities
            // when it encounters entities that span across multiple pages.
            // 1 -  In visual order:
            // When moving through an entity's children that span multiple pages,
            // page layout takes precedence, and we move to other child elements on this page and avoid the ones on the next.
            Console.WriteLine("Traversing from first to last, elements between pages separated:");
            TraverseLayoutForward(layoutEnumerator, 1);

            // Our enumerator is now at the end of the collection. We can traverse the layout entities backwards to go back to the beginning.
            Console.WriteLine("Traversing from last to first, elements between pages separated:");
            TraverseLayoutBackward(layoutEnumerator, 1);

            // 2 -  In logical order:
            // When moving through an entity's children that span multiple pages,
            // the enumerator will move between pages to traverse all the child entities.
            Console.WriteLine("Traversing from first to last, elements between pages mixed:");
            TraverseLayoutForwardLogical(layoutEnumerator, 1);

            Console.WriteLine("Traversing from last to first, elements between pages mixed:");
            TraverseLayoutBackwardLogical(layoutEnumerator, 1);
        }
        public static void Run(Document doc, LayoutEnumerator layoutEnumerator, string folderPath)
        {
            // Make sure the enumerator is at the beginning of the document.
            layoutEnumerator.Reset();

            for (int pageIndex = 0; pageIndex < doc.PageCount; pageIndex++)
            {
                // Use the document class to find information about the current page.
                PageInfo pageInfo = doc.GetPageInfo(pageIndex);

                const float resolution = 150.0f;
                Size        pageSize   = pageInfo.GetSizeInPixels(1.0f, resolution);

                using (Bitmap img = new Bitmap(pageSize.Width, pageSize.Height))
                {
                    img.SetResolution(resolution, resolution);

                    using (Graphics g = Graphics.FromImage(img))
                    {
                        // Make the background white.
                        g.Clear(Color.White);

                        // Render the page to the graphics.
                        doc.RenderToScale(pageIndex, g, 0.0f, 0.0f, 1.0f);

                        // Add an outline around each element on the page using the graphics object.
                        AddBoundingBoxToElementsOnPage(layoutEnumerator, g);

                        // Move the enumerator to the next page if there is one.
                        layoutEnumerator.MoveNext();

                        img.Save(folderPath + $"EnumerateLayoutElements.Page_{pageIndex + 1}.png");
                    }
                }
            }
        }
        [Test] //ExSkip
        public void LayoutEnumerator()
        {
            // Open a document that contains a variety of layout entities
            // Layout entities are pages, cells, rows, lines and other objects included in the LayoutEntityType enum
            // They are defined visually by the rectangular space that they occupy in the document
            Document doc = new Document(MyDir + "Layout entities.docx");

            // Create an enumerator that can traverse these entities like a tree
            LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);

            Assert.AreEqual(doc, layoutEnumerator.Document);

            layoutEnumerator.MoveParent(LayoutEntityType.Page);
            Assert.AreEqual(LayoutEntityType.Page, layoutEnumerator.Type);
            Assert.Throws <InvalidOperationException>(() => Console.WriteLine(layoutEnumerator.Text));

            // We can call this method to make sure that the enumerator points to the very first entity before we go through it forwards
            layoutEnumerator.Reset();

            // "Visual order" means when moving through an entity's children that are broken across pages,
            // page layout takes precedence and we avoid elements in other pages and move to others on the same page
            Console.WriteLine("Traversing from first to last, elements between pages separated:");
            TraverseLayoutForward(layoutEnumerator, 1);

            // Our enumerator is conveniently at the end of the collection for us to go through the collection backwards
            Console.WriteLine("Traversing from last to first, elements between pages separated:");
            TraverseLayoutBackward(layoutEnumerator, 1);

            // "Logical order" means when moving through an entity's children that are broken across pages,
            // node relationships take precedence
            Console.WriteLine("Traversing from first to last, elements between pages mixed:");
            TraverseLayoutForwardLogical(layoutEnumerator, 1);

            Console.WriteLine("Traversing from last to first, elements between pages mixed:");
            TraverseLayoutBackwardLogical(layoutEnumerator, 1);
        }
        public static void Run(Document doc, LayoutEnumerator it, string folderPath)
        {
            // Make sure the enumerator is at the beginning of the document.
            it.Reset();

            for (int pageIndex = 0; pageIndex < doc.PageCount; pageIndex++)
            {
                // Use the document class to find information about the current page.
                PageInfo pageInfo = doc.GetPageInfo(pageIndex);

                const float resolution = 150.0f;
                Size pageSize = pageInfo.GetSizeInPixels(1.0f, resolution);

                using (Bitmap img = new Bitmap(pageSize.Width, pageSize.Height))
                {
                    img.SetResolution(resolution, resolution);

                    using (Graphics g = Graphics.FromImage(img))
                    {
                        // Make the background white.
                        g.Clear(Color.White);

                        // Render the page to the graphics.
                        doc.RenderToScale(pageIndex, g, 0.0f, 0.0f, 1.0f);

                        // Add an outline around each element on the page using the graphics object.
                        AddBoundingBoxToElementsOnPage(it, g);

                        // Move the enumerator to the next page if there is one.
                        it.MoveNext();

                        img.Save(folderPath + string.Format("TestFile Page {0} Out.png", pageIndex + 1));
                    }
                }
            }
        }
        public void LayoutCollector()
        {
            //ExStart
            //ExFor:Layout.LayoutCollector
            //ExFor:Layout.LayoutCollector.#ctor(Document)
            //ExFor:Layout.LayoutCollector.Clear
            //ExFor:Layout.LayoutCollector.Document
            //ExFor:Layout.LayoutCollector.GetEndPageIndex(Node)
            //ExFor:Layout.LayoutCollector.GetEntity(Node)
            //ExFor:Layout.LayoutCollector.GetNumPagesSpanned(Node)
            //ExFor:Layout.LayoutCollector.GetStartPageIndex(Node)
            //ExFor:Layout.LayoutEnumerator.Current
            //ExSummary:Shows how to see the page spans of nodes.
            // Open a blank document and create a DocumentBuilder
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Create a LayoutCollector object for our document that will have information about the nodes we placed
            LayoutCollector layoutCollector = new LayoutCollector(doc);

            // The document itself is a node that contains everything, which currently spans 0 pages
            Assert.AreEqual(doc, layoutCollector.Document);
            Assert.AreEqual(0, layoutCollector.GetNumPagesSpanned(doc));

            // Populate the document with sections and page breaks
            builder.Write("Section 1");
            builder.InsertBreak(BreakType.PageBreak);
            builder.InsertBreak(BreakType.PageBreak);
            doc.AppendChild(new Section(doc));
            doc.LastSection.AppendChild(new Body(doc));
            builder.MoveToDocumentEnd();
            builder.Write("Section 2");
            builder.InsertBreak(BreakType.PageBreak);
            builder.InsertBreak(BreakType.PageBreak);

            // The collected layout data won't automatically keep up with the real document contents
            Assert.AreEqual(0, layoutCollector.GetNumPagesSpanned(doc));

            // After we clear the layout collection and update it, the layout entity collection will be populated with up-to-date information about our nodes
            // The page span for the document now shows 5, which is what we would expect after placing 4 page breaks
            layoutCollector.Clear();
            doc.UpdatePageLayout();
            Assert.AreEqual(5, layoutCollector.GetNumPagesSpanned(doc));

            // We can also see the start/end pages of any other node, and their overall page spans
            NodeCollection nodes = doc.GetChildNodes(NodeType.Any, true);

            foreach (Node node in nodes)
            {
                Console.WriteLine($"->  NodeType.{node.NodeType}: ");
                Console.WriteLine(
                    $"\tStarts on page {layoutCollector.GetStartPageIndex(node)}, ends on page {layoutCollector.GetEndPageIndex(node)}," +
                    $" spanning {layoutCollector.GetNumPagesSpanned(node)} pages.");
            }

            // We can iterate over the layout entities using a LayoutEnumerator
            LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);

            Assert.AreEqual(LayoutEntityType.Page, layoutEnumerator.Type);

            // The LayoutEnumerator can traverse the collection of layout entities like a tree
            // We can also point it to any node's corresponding layout entity like this
            layoutEnumerator.Current = layoutCollector.GetEntity(doc.GetChild(NodeType.Paragraph, 1, true));
            Assert.AreEqual(LayoutEntityType.Span, layoutEnumerator.Type);
            Assert.AreEqual("¶", layoutEnumerator.Text);
            //ExEnd
        }
 public static void Run(LayoutEnumerator layoutEnumerator)
 {
     DisplayLayoutElements(layoutEnumerator, string.Empty);
 }
        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);
        }
Example #27
0
        public void LayoutCollector()
        {
            //ExStart
            //ExFor:Layout.LayoutCollector
            //ExFor:Layout.LayoutCollector.#ctor(Document)
            //ExFor:Layout.LayoutCollector.Clear
            //ExFor:Layout.LayoutCollector.Document
            //ExFor:Layout.LayoutCollector.GetEndPageIndex(Node)
            //ExFor:Layout.LayoutCollector.GetEntity(Node)
            //ExFor:Layout.LayoutCollector.GetNumPagesSpanned(Node)
            //ExFor:Layout.LayoutCollector.GetStartPageIndex(Node)
            //ExFor:Layout.LayoutEnumerator.Current
            //ExSummary:Shows how to see the the ranges of pages that a node spans.
            Document        doc             = new Document();
            LayoutCollector layoutCollector = new LayoutCollector(doc);

            // Call the "GetNumPagesSpanned" method to count how many pages the content of our document spans.
            // Since the document is empty, that number of pages is currently zero.
            Assert.AreEqual(doc, layoutCollector.Document);
            Assert.AreEqual(0, layoutCollector.GetNumPagesSpanned(doc));

            // Populate the document with 5 pages of content.
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.Write("Section 1");
            builder.InsertBreak(BreakType.PageBreak);
            builder.InsertBreak(BreakType.PageBreak);
            builder.InsertBreak(BreakType.SectionBreakEvenPage);
            builder.Write("Section 2");
            builder.InsertBreak(BreakType.PageBreak);
            builder.InsertBreak(BreakType.PageBreak);

            // Before the layout collector, we need to call the "UpdatePageLayout" method to give us
            // an accurate figure for any layout-related metric, such as the page count.
            Assert.AreEqual(0, layoutCollector.GetNumPagesSpanned(doc));

            layoutCollector.Clear();
            doc.UpdatePageLayout();

            Assert.AreEqual(5, layoutCollector.GetNumPagesSpanned(doc));

            // We can see the numbers of the start and end pages of any node and their overall page spans.
            NodeCollection nodes = doc.GetChildNodes(NodeType.Any, true);

            foreach (Node node in nodes)
            {
                Console.WriteLine($"->  NodeType.{node.NodeType}: ");
                Console.WriteLine(
                    $"\tStarts on page {layoutCollector.GetStartPageIndex(node)}, ends on page {layoutCollector.GetEndPageIndex(node)}," +
                    $" spanning {layoutCollector.GetNumPagesSpanned(node)} pages.");
            }

            // We can iterate over the layout entities using a LayoutEnumerator.
            LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);

            Assert.AreEqual(LayoutEntityType.Page, layoutEnumerator.Type);

            // The LayoutEnumerator can traverse the collection of layout entities like a tree.
            // We can also apply it to any node's corresponding layout entity.
            layoutEnumerator.Current = layoutCollector.GetEntity(doc.GetChild(NodeType.Paragraph, 1, true));

            Assert.AreEqual(LayoutEntityType.Span, layoutEnumerator.Type);
            Assert.AreEqual("¶", layoutEnumerator.Text);
            //ExEnd
        }
Example #28
0
            public LineCounter(Document doc)
            {
                mLayoutEnumerator = new LayoutEnumerator(doc);

                CountLines();
            }
 public static void Run(LayoutEnumerator it)
 {
     DisplayLayoutElements(it, string.Empty);
 }