Selected text of a page or all pages in the document as a simple string object.
public string GetSelectedText(int pageNumber)
pageNumber
Page number to use. If this value is 0, then the text of all pages in the document will be used.
The selected text of the page or the document as a simple string object, or an empty string if no selected text was found.
If the text of the specified page(s) was not previously obtained, then the value of AutoGetText will be used to determine whether DocumentPage.GetText is called automatically. Therefore, this method might experience a delay while the text is parsed from the document in this mode.
using Leadtools;using Leadtools.Controls;using Leadtools.Document;using Leadtools.Document.Viewer;using Leadtools.Codecs;using Leadtools.Caching;using Leadtools.Annotations.Engine;using Leadtools.Ocr;var text = _documentViewer.Text;// First check if we have text for this pagevar pageNumber = _documentViewer.CurrentPageNumber;if (!text.HasDocumentPageText(pageNumber)){// Get the texttext.GetDocumentPageText(pageNumber);// Show itvar value = text.ExportText(pageNumber);Console.WriteLine(value);}// Get the current documentvar document = _documentViewer.Document;// Get the page and the current view itemvar page = document.Pages[pageNumber - 1];// Create a rectangle that is the first half of the pagevar bounds = LeadRectD.Create(0, 0, page.Size.Width, page.Size.Height / 2);// SelectText requires the rectangle to be in control pixel coordinates, so convert. First to pixels ...bounds = document.RectToPixels(bounds).ToLeadRectD();// And then using the image viewer in the view to control. The item is the one at page number - 1var imageViewer = _documentViewer.View.ImageViewer;bounds = imageViewer.ConvertRect(imageViewer.Items[pageNumber - 1], ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, bounds);// Select it, all linestext.SelectText(bounds.ToLeadRect(), DocumentViewerSelectTextMode.Line);// Now, check if we have any text selectedif (text.HasSelectedText(pageNumber)){// yes, show itvar value = text.GetSelectedText(pageNumber);Console.WriteLine(value);}