//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Pdf.Annotations;usingSystem.Collections.Generic;usingGrapeCity.Documents.Common; namespaceDsPdfWeb.Demos{// This example shows how to find all occurrences of a word in a PDF document// and highlight all those occurrences using the text markup highlight annotation.// This example creates a text markup annotation per occurrence. A different approach // illustrated in MarkupPerPage is to create a text markup annotation per page.//// The PDF used in this example was downloaded from https://www.frontiersin.org/articles/10.3389/fendo.2022.1005722/full.publicclassFindAndHighlight {publicintCreatePDF(Stream stream) {// Load the PDF:var doc = newGcPdfDocument();usingvar fs = File.OpenRead(Path.Combine("Resources", "PDFs", "fendo-13-1005722.pdf")); doc.Load(fs); // Find all occurrences of the word "childbirths":var found = doc.FindText(newFindTextParams("childbirths", true, false), null); // Add a text markup annotation to highlight each occurrence:foreach (var f in found) {var markup = newTextMarkupAnnotation() {Page = doc.Pages[f.PageIndex],MarkupType = TextMarkupType.Highlight,Color = Color.Yellow };List<Quadrilateral> area = newList<Quadrilateral>();foreach (var b in f.Bounds) area.Add(b); markup.Area = area; } // Done: doc.Save(stream);return doc.Pages.Count; } }}