Search for specific text in a PDF document and you will notice that if the document is landscape, the SearchResult.GetWordBoundingRect method may return incorrect results. If the document is Portrait, the exact results are highlighted with the code snippet below:
PdfFormatProvider provider = new PdfFormatProvider();
RadFixedDocument document = provider.Import(File.ReadAllBytes("Landscape.pdf"));
TextSearch searchText = new TextSearch(document);
TextSearchOptions searchOptions = new TextSearchOptions { UseRegularExpression=false, CaseSensitive=false, WholeWordsOnly = true };
IEnumerable<SearchResult> matchResults = searchText.FindAll("sed", searchOptions);
foreach (SearchResult resultItem in matchResults)
{
Rect rect = resultItem.GetWordBoundingRect();
RadFixedPage page = resultItem.GetResultPage();
FixedContentEditor editor = new FixedContentEditor(page);
editor.GraphicProperties.FillColor = new RgbColor(125, 255, 0, 0);
editor.DrawRectangle(rect);
}
string outputFilePath = "result.pdf";
File.Delete(outputFilePath);
File.WriteAllBytes(outputFilePath, provider.Export(document));
Process.Start(new ProcessStartInfo() { FileName = outputFilePath, UseShellExecute = true });
Landscape: wrong rectangles are highlighted
Portrait: correct rectangles are highlighted: