Search
Search the document shown in a .NET MAUI PdfView and jump to the page of each match.
License module
Search is part of the viewer module and works without a key.
PdfView has no search bar in 1.1. Search with view.Document.SearchJson(query) and move the view
with GoToPageAsync:
using System.Text.Json.Nodes;
var doc = view.Document!;
var hits = JsonNode.Parse(await Task.Run(() => doc.SearchJson(query)))!.AsArray();
ResultsLabel.Text = $"{hits.Count} matches";
if (hits.Count > 0)
await view.GoToPageAsync(hits[0]!["page"]!.GetValue<int>());Each hit has page (0-based), context (the text around the match) and the rectangle llx,
lly, urx, ury in PDF points.
Highlight the matches
With the annotations module, add highlights and reload the view:
foreach (var hit in hits)
{
double N(string k) => hit![k]!.GetValue<double>();
doc.AddAnnotation(hit!["page"]!.GetValue<int>(), "Highlight", "#FFD400", 1.0, "",
N("llx"), N("lly"), N("urx"), N("ury"));
}
await view.ReloadAsync();To remove the matches permanently, see Redaction.