new TextController()
WebDocumentViewer Text Layer operations API.
Classes
Methods
clearSelection()
Clears all text selection for the document.
copySelected()
Copies selected text to clipboard. This method don't depend on TextMouseToolConfig.hookcopy
config option, i.e. text will be copied if ctrl+c
copying is disabled for user.
getPageText(index, successopt, failopt)
Returns all text for the specified page.
Parameters:
Name | Type | Description |
---|---|---|
index |
number | Index of the page to retrieve text. |
[success] |
GetPageTextCallback | function that that is called when page text is loaded and formatted. |
[fail] |
NotificationCallback | Function that that is called when page text load is failed. |
getSelected() → {string}
Retrieves the selected text.
Returns:
Selected text. Line break is inserted after each line and region.
- Type
- string
isPageTextLoaded(index)
Indicates whether page text is loaded.
Parameters:
Name | Type | Description |
---|---|---|
index |
number | Index of the page to check text data state. |
reloadPageText(index, successopt, failopt)
Forcibly triggers page text load.
Parameters:
Name | Type | Description |
---|---|---|
index |
number | Index of the page to reset text data. |
[success] |
LoadPageTextCallback | Function that that is called when page text is loaded successfully. |
[fail] |
LoadPageTextCallback | Function that that is called when page text load is failed. |
resetPageText(indexopt)
Marks page text data for reload. After this call text data will be loaded next time page will be inserted into DOM on scrolling. I.e. this method won't triggered immediate text reload, even for visible pages.
Parameters:
Name | Type | Description |
---|---|---|
[index] |
number | Index of the page to reset text data. If not specified whole document text data is reset. |
searchOnPages(text, startPageopt, endPageopt, activePageopt, callbackopt)
Triggers text search for the specified pages. This method also triggers UI search behavior - highlight for matched text occurrences selection of current text result and scrolling during text results iteration.
Parameters:
Name | Type | Description |
---|---|---|
text |
string | Text to search for. The text must be at least 3 characters long. |
[startPage] |
number | Index of the page to start search from. If not specified first page in document is assumed to be the first in search. |
[endPage] |
number | Index of the page to end search where. If not specified last page in document is assumed to be the last in search. |
[activePage] |
number | Index of the page from that viewer should start scrolling to the next search result. |
[callback] |
TextSearchCallback | Search callback that receives search results iterator. |
Returns:
If callback is specified - search results iterator that allows navigation over search results, otherwise null.
selectPageText(index, regionopt, lineopt, wordopt, successopt, failopt)
Selects all text on the page.
Any optional arguments could be omitted and callback could be passed instead of it.
This method is intended to select whole page text or to be used in conjunction with text search API when region
, line
, word
indexes are passed to application using search iterator.
Parameters:
Name | Type | Description |
---|---|---|
index |
number | Index of the page to select page on. |
[region] |
number | Index of the region to select. |
[line] |
number | Index of the line to select. |
[word] |
number | Index of the word to select. |
[success] |
NotificationCallback | Function that that is called when page text is loaded and selected. |
[fail] |
NotificationCallback | Function that that is called when page text load is failed. |
Example
<caption> Search text occurrence and automatically select it. Note, that `match.word` is the index of the first word in matched text. If search phrase contain multiple words, only firs will be selected in this example. </caption>
_viewer.text.search('findme', 0, function (it, match) {
if (it.isValid()) {
_viewer.text.selectPageText(match.page, match.region, match.line, match.word);
}
});
search(text, startPageopt, callbackopt)
Triggers text search. This method also triggers UI search behavior - highlight for matched text occurrences selection of current text result and scrolling during text results iteration.
Parameters:
Name | Type | Description |
---|---|---|
text |
string | Text to search for. The text must be at least 3 characters long. |
[startPage] |
number | Index of the page to start search from. If not specified first page in document is assumed to be the first in search. |
[callback] |
TextSearchCallback | Search callback that receives search results iterator. |
- Deprecated:
- - Use the
searchOnPages
method instead.
- - Use the
Returns:
If callback is specified - search results iterator that allows navigation over search results, otherwise null.