//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Drawing;usingSystem.Collections.Generic;usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Pdf.Annotations;usingGrapeCity.Documents.Pdf.Structure;usingGrapeCity.Documents.Pdf.Recognition.Structure; namespaceDsPdfWeb.Demos{// Highlight paragraphs which have associated structure tags.publicclassReadTagsShowParas {publicintCreatePDF(Stream stream) {var user = "DsPdfWeb Demo"; var doc = newGcPdfDocument();usingvar 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:voidremoveStructNodesForPage(StructElementCollection ses, Page p) {for (int i = ses.Count - 1; i >= 0; --i) {var se = ses[i];if (se.DefaultPage == p) ses.RemoveAt(i);elseremoveStructNodesForPage(se.Children, p); } }for (int i = doc.Pages.Count - 1; i >= 5; --i) {removeStructNodesForPage(doc.StructTreeRoot.Children, doc.Pages[i]); doc.Pages.RemoveAt(i); } // 2nd step - get the logical structure, highlight paragraphs// and add sticky notes to them:voidhighlightParagraphs(IReadOnlyList<Element> items) {var color = Color.FromArgb(64, Color.Magenta);foreach (var e in items) {if (e.HasContentItems)foreach (var i in e.ContentItems) {if (i isContentItem ci) {var p = ci.GetParagraph();if (p != null) {var rc = p.GetCoords().ToRect(); rc.Offset(rc.Width, 0); rc.Size = newSizeF(16, 12);var ta = newTextAnnotation() {UserName = user,Rect = rc,Page = ci.Page,Contents = p.GetText(),Color = Color.Yellow, }; ci.Page.Graphics.DrawPolygon(p.GetCoords(), color, 1, null); } } }if (e.HasChildren)highlightParagraphs(e.Children); } }// Get the LogicalStructure and use it to highlight paragraphs:LogicalStructure ls = doc.GetLogicalStructure();highlightParagraphs(ls.Elements); // Done: doc.Save(stream);return doc.Pages.Count; } }}