Error processing SSI file
LEADTOOLS Leadtools.Documents.UI (Leadtools.Documents.UI assembly)

DocumentViewerText Object

Show in webframe
Example 
Members 
Manages the text operations in this document viewer.
Object Model
Syntax
function Leadtools.Documents.UI.DocumentViewerText() 
Remarks

DocumentViewerText can be accessed by the Text property of DocumentViewer. An instance is always available when the control is created and is never null.

This class manages the text operations of the current Document set in the document viewer. The text is treated as a read-only option and cannot be changed. The operations that can be performed includes selecting characters, words or lines using the mouse or touch, highlighting the selected text of the pages, performing free text search in the document using "find", "find next" and "find previous" and exporting the text as a simple string or to the clipboard.

The text of a document page is obtained using the DocumentPage.GetText method. This parses any text elements found on a page using SVG or OCR technologies and returns it in a DocumentPageText object that contains the character code, location and size of each text character found in the page.

The DocumentViewerTextItem class contains information of a selected text item on a page. This includes the page number, the bounding rectangle of the selection as well as the range of the characters selected in the corresponding DocumentPageText.

DocumentViewerText keeps track of the selection state internally in a list of DocumentViewerTextItem items. When the text selection changes, this list is updated to reflect the current state. These items are also used to highlight the current text selection on DocumentViewer.View.ImageViewer.

DocumentViewerSelectTextInteractiveMode uses the methods of DocumentViewerText to perform its main action of selecting text interactively using mouse or touch. The draw designers of the AnnTextReviewObject objects such as highlight, underline strikeout and text redaction also uses the methods of this class to perform their actions if annotations support is used.

Obtaining the text can be a time consuming operation especially if OCR is used. Therefore, DocumentViewerText tries to obtain the text only as needed and then stores the DocumentPageText items internally and re-uses them.

The AutoGetText property controls how text is obtained and should be set according to the application need.

DocumentViewerText uses the Operation event to inform the user when text is obtained from the document and if the text selection changes. Refer to Document Viewer Operations for more information.

In addition to the methods of this class, the application can use the commands system to interact with the text. Refer to the Text section in Document Viewer Commands for more information.

Example

Start with the example created in DocumentViewer, remove all the code in the Example function and add the code below.

When the user clicks the Example button, we will select all the text at the top half of the current page.

var text = this._documentViewer.text;

// First check if we have text for this page
var pageNumber = this._documentViewer.currentPageNumber;
if (!text.hasDocumentPageText(pageNumber)) {
   // Get the text
   text.getDocumentPageText(pageNumber);
   // Show it
   var value = text.exportText(pageNumber);
   alert(value);
}

// Get the current document
var document = this._documentViewer.document;
// Get the page and the current view item
var page = document.pages.at(pageNumber - 1);
// Create a rectangle that is the first half of the page
var bounds = lt.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);
// And then using the image viewer in the view to control. The item is the one at page number - 1
var imageViewer = this._documentViewer.view.imageViewer;
bounds = imageViewer.convertRect(imageViewer.items.at(pageNumber - 1), lt.Controls.ImageViewerCoordinateType.image, lt.Controls.ImageViewerCoordinateType.control, bounds);
// Select it, all lines
text.selectText(bounds, lt.Documents.UI.DocumentViewerSelectTextMode.line);

// Now, check if we have any text selected
if (text.hasSelectedText(pageNumber)) {
   // yes, show it
   var value = text.getSelectedText(pageNumber);
   alert(value);
}
See Also

Reference

DocumentViewerText Members
Leadtools.Documents.UI Namespace
Using LEADTOOLS Document Viewer

Error processing SSI file
  Leadtools.Documents.UI requires a Document or Medical toolkit license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features