/// <summary> /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Visual" order. /// </summary> private static void TraverseLayoutForward(LayoutEnumerator layoutEnumerator, int depth) { do { PrintCurrentEntity(layoutEnumerator, depth); if (layoutEnumerator.MoveFirstChild()) { TraverseLayoutForward(layoutEnumerator, depth + 1); layoutEnumerator.MoveParent(); } } while (layoutEnumerator.MoveNext()); }
/// <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()); }
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"); } } } }
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)); } } } }