'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.LinqImportsSystem.Collections.GenericImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.Pdf.StructureImportsGrapeCity.Documents.Pdf.Recognition.Structure '' Find tables and read their data using structure tags.PublicClassReadTagsToOutlinesPublicFunctionCreatePDF(ByVal stream AsStream) AsIntegerDim doc = NewGcPdfDocument()Using s = File.OpenRead(Path.Combine("Resources", "PDFs", "C1Olap-QuickStart.pdf")) doc.Load(s) '' Get the LogicalStructure and top parent element:Dim ls AsLogicalStructure = doc.GetLogicalStructure()Dim root AsElement = ls.Elements(0) '' Iterate over elements and select all heading elements (H1, H2, H3 etc.):Dim outlines AsOutlineNodeCollection = doc.OutlinesDim outlinesLevel = 1ForEach e AsElementIn root.ChildrenDim eType = e.StructElement.TypeIfString.IsNullOrEmpty(eType) OrElseNot eType.StartsWith("H") ThenContinueForEndIf' Note: topmost level is 1:Dim headingLevel AsInteger = 0IfNotInteger.TryParse(eType.Substring(1), headingLevel) OrElse headingLevel < 1ThenContinueForEndIf' Get the element text:Dim text = e.GetText()' Find the target page:Dim pg = FindPage(e.StructElement)If pg IsNotNothingThenDim o = NewOutlineNode(text, NewDestinationFit(pg))If headingLevel > outlinesLevel Then outlinesLevel += 1 outlines = outlines.Last().ChildrenElseIf headingLevel < outlinesLevel Then outlinesLevel -= 1Dim par = DirectCast(outlines.Owner, OutlineNode).Parent outlines = If(par IsNothing, doc.Outlines, par.Children)EndIf outlines.Add(o)EndIfNext doc.Save(stream)'' Done:Return doc.Pages.CountEndUsingEndFunction PrivateFunctionFindPage(se AsStructElement) AsPageIf se.DefaultPageIsNotNothingThenReturn se.DefaultPageEndIfIf se.HasChildrenThenForEach child In se.ChildrenDim p = FindPage(child)If p IsNotNothingThenReturn pEndIfNextEndIfReturnNothingEndFunctionEndClass