/// <summary> /// Drawing the pages with highlighted text. /// </summary> /// <param name="handlerArgs"> The handler args. </param> private static void SearchHandler(SearchHandlerArgs handlerArgs) { if (handlerArgs.ResultItems.Count != 0) { string outputFileName = $"{handlerArgs.PageIndex}.png"; Page page = document.Pages[handlerArgs.PageIndex]; using (Image bm = page.Render((int)page.Width * 2, (int)page.Height * 2, renderingSettings)) { foreach (SearchResultItem searchResultItem in handlerArgs.ResultItems) { HighlightSearchResult(bm, searchResultItem, page); } bm.Save(outputFileName); } Process.Start(outputFileName); } // Search cancellation condition, now we stop if we have more than 3 results found, // or all pages are searched if (handlerArgs.ResultItems.Count > 3) { handlerArgs.CancelSearch = true; } }
/// <summary> /// Called when generate a digest of found items. /// </summary> /// <param name="handlerargs"> The handler args. </param> private void OnSearchItem(SearchHandlerArgs handlerargs) { if (!(handlerargs.CancelSearch = CancelSearching)) { try { Invoke(new Action(delegate { if (handlerargs.ResultItems.Count != 0) { string fileName = Path.GetFileName(currentSearchFileName); ListViewGroup group = currentGroup; if (currentGroup == null || currentGroup.Header != fileName) { group = currentGroup = new ListViewGroup(fileName); resultsView.Groups.Add(group); group.HeaderAlignment = HorizontalAlignment.Left; } foreach (SearchResultItem searchResultItem in handlerargs.ResultItems) { ListViewItem item = new ListViewItem(string.Format("'{0}' on the page {1}", searchResultItem.Title, searchResultItem.PageIndex), group); item.Tag = new ResultItem(searchResultItem, currentSearchFileName); resultsView.Items.Add(item); } } })); } catch (Exception e) { Debug.WriteLine(e); } } else { Debug.WriteLine("Canceled"); } }
/// Drawing the pages with highlighted text. private static void SearchHandler(SearchHandlerArgs handlerArgs) { if (handlerArgs.ResultItems.Count != 0) { string outputFileName = string.Format("{0}.png", handlerArgs.PageIndex); Page page = document.Pages[handlerArgs.PageIndex]; using (Image bm = page.Render((int)page.Width * 2, (int)page.Height * 2, renderingSettings)) { foreach (SearchResultItem searchResultItem in handlerArgs.ResultItems) { HighlightSearchResult(bm, searchResultItem, page); } bm.Save(outputFileName); } Process.Start(outputFileName); } // Search cancellation condition, now we stop if we have more than 3 results found, // or all pages are searched if (handlerArgs.ResultItems.Count > 3) { handlerArgs.CancelSearch = true; } }