//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.// usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Common;usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Pdf.Layers; namespaceDsPdfWeb.Demos{// This example shows how to search for text in certain layers only. // The input PDF for this sample was created by LangLayers.publicclassSearchInLayers {publicintCreatePDF(Stream stream) {usingvar fs = File.OpenRead(Path.Combine("Resources", "PDFs", "lang-layers.pdf"));var doc = newGcPdfDocument(); doc.Load(fs); var regex = "\\b(Windows|macOS|Linux|Mac)\\b";// var regex = @"(?=(\W|^))(shoes|shirt|pants)(?!(\W|$))";FindInLayer(doc, "English", regex, Color.FromArgb(100, Color.Red));FindInLayer(doc, "French", regex, Color.FromArgb(100, Color.Blue));FindInLayer(doc, "Russian", regex, Color.FromArgb(100, Color.Green)); // Save the PDF: doc.Save(stream);return doc.Pages.Count; } staticvoidFindInLayer(GcPdfDocument doc, string layer, string text, Color highlight) {// Create a view state with just the specified layer visible:var viewState = newViewState(doc); viewState.SetLayersUIStateExcept(false, layer); viewState.SetLayersUIState(true, layer); // Create a FindTextParams using our custom view state// so that the search is limited to the specified layer only:var ftp = newFindTextParams(text, false, false, viewState, 72f, 72f, true, true); // Find all occurrences of the search text:var finds = doc.FindText(ftp, OutputRange.All); // Highlight all occurrences on the specified layer only:foreach (var find in finds)foreach (var ql in find.Bounds) {var g = doc.Pages[find.PageIndex].Graphics; g.BeginLayer(layer); doc.Pages[find.PageIndex].Graphics.FillPolygon(ql, highlight); g.EndLayer(); } } }}