'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsSystem.LinqImportsSystem.Collections.GenericImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.Pdf.AnnotationsImportsGrapeCity.Documents.Pdf.StructureImportsGrapeCity.Documents.Pdf.Recognition.Structure '' Highlight paragraphs which have associated structure tags.PublicClassReadTagsShowParasPublicFunctionCreatePDF(ByVal stream AsStream) AsIntegerDim user = "DsPdfWeb Demo" Dim doc = NewGcPdfDocument()Using s = File.OpenRead(Path.Combine("Resources", "PDFs", "C1Olap-QuickStart.pdf")) doc.Load(s) '' 1st step - remove all but the first 5 pages from the loaded PDF,' also removing tags that point to the removed pages:For i = doc.Pages.Count - 1To5Step -1RemoveStructNodesForPage(doc.StructTreeRoot.Children, doc.Pages(i)) doc.Pages.RemoveAt(i)Next '' 2nd step - get the logical structure, highlight paragraphs' and add sticky notes to them:Dim ls AsLogicalStructure = doc.GetLogicalStructure()HighlightParagraphs(ls.Elements, user) '' Done: doc.Save(stream)Return doc.Pages.CountEndUsingEndFunction PrivateSubRemoveStructNodesForPage(ses AsStructElementCollection, p AsPage)For i = ses.Count - 1To0Step -1Dim se = ses(i)If se.DefaultPageIs p Then ses.RemoveAt(i)ElseRemoveStructNodesForPage(se.Children, p)EndIfNextEndSub PrivateSubHighlightParagraphs(items AsIReadOnlyList(OfElement), user AsString)Dim colorVal = Color.FromArgb(64, Color.Magenta)ForEach e In itemsIf e.HasContentItemsThenForEach i In e.ContentItemsIfTypeOf i IsContentItemThenDim ci = DirectCast(i, ContentItem)Dim p = ci.GetParagraph()If p IsNotNothingThenDim rc = p.GetCoords().ToRect() rc.Offset(rc.Width, 0) rc.Size = NewSizeF(16, 12)Dim ta = NewTextAnnotation() With { .UserName = user, .Rect = rc, .Page = ci.Page, .Contents = p.GetText(), .Color = Color.Yellow } ci.Page.Graphics.DrawPolygon(p.GetCoords(), colorVal)EndIfEndIfNextEndIfIf e.HasChildrenThenHighlightParagraphs(e.Children, user)EndIfNextEndSubEndClass