//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Linq;usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Pdf.Structure;usingGrapeCity.Documents.Pdf.Recognition.Structure; namespaceDsPdfWeb.Demos{// Find tables and read their data using structure tags.publicclassReadTagsToOutlines {publicintCreatePDF(Stream stream) {var doc = newGcPdfDocument();usingvar s = File.OpenRead(Path.Combine("Resources", "PDFs", "C1Olap-QuickStart.pdf")); doc.Load(s); // Get the LogicalStructure and top parent element:LogicalStructure ls = doc.GetLogicalStructure();Element root = ls.Elements[0]; // Iterate over elements and select all heading elements (H1, H2, H3 etc.):OutlineNodeCollection outlines = doc.Outlines;int outlinesLevel = 1;foreach (Element e in root.Children) {string type = e.StructElement.Type;if (string.IsNullOrEmpty(type) || !type.StartsWith("H"))continue;// Note: topmost level is 1:if (!int.TryParse(type.Substring(1), outint headingLevel) || headingLevel < 1)continue;// Get the element text:string text = e.GetText();// Find the target page:var page = FindPage(e.StructElement);if (page != null) {var o = newOutlineNode(text, newDestinationFit(page));if (headingLevel > outlinesLevel) { ++outlinesLevel; outlines = outlines.Last().Children; }elseif (headingLevel < outlinesLevel) { --outlinesLevel;var p = ((OutlineNode)outlines.Owner).Parent; outlines = p == null ? doc.Outlines : p.Children; } outlines.Add(o); } } doc.Save(stream);return doc.Pages.Count; } privatePageFindPage(StructElement se) {if (se.DefaultPage != null)return se.DefaultPage;if (se.HasChildren)foreach (var child in se.Children) {var p = FindPage(child);if (p != null)return p; }returnnull; } }}