//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem;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 two words in a PDF document and// underline those occurrences using the text markup underline annotation. // This example is similar to FindAndUnderline, but here we create one text markup// annotation per page, adding all occurrences of the words to highlight to it,// rather than adding a separate annotation for each occurrence.publicclassMarkupPerPage {publicintCreatePDF(Stream stream) {// Load the PDF:var doc = newGcPdfDocument();usingvar fs = File.OpenRead(Path.Combine("Resources", "PDFs", "The-Rich-History-of-JavaScript.pdf")); doc.Load(fs); // Find all occurrences of "JavaScript" or "ECMAScript" using regex:var ft = newFindTextParams("JavaScript|ECMAScript", wholeWord: false, matchCase: false, regex: true);var found = doc.FindText(ft, null); // Add a text markup annotation per page (keys are page indices):Dictionary<int, Tuple<TextMarkupAnnotation, List<Quadrilateral>>> markups = newDictionary<int, Tuple<TextMarkupAnnotation, List<Quadrilateral>>>();foreach (var f in found) {if (!markups.TryGetValue(f.PageIndex, outvar markup)) { markup = newTuple<TextMarkupAnnotation, List<Quadrilateral>>(newTextMarkupAnnotation() {Page = doc.Pages[f.PageIndex],MarkupType = TextMarkupType.Highlight,Color = Color.Chartreuse },newList<Quadrilateral>()); markups[f.PageIndex] = markup; }foreach (var b in f.Bounds) markup.Item2.Add(b); }foreach (var v in markups.Values) v.Item1.Area = v.Item2; // Done: doc.Save(stream);return doc.Pages.Count; } }}