Wrap text search to current page.

56 views
Skip to first unread message

Matt Bojey

unread,
Aug 20, 2015, 5:54:10 PM8/20/15
to PDFTron WebViewer
Q

How can I make the text search wrap around the document and keep going until it reaches the page it started from?

A

You can put this in your config file to achieve the desired behaviour:

ReaderControl.prototype.searchText = function(pattern, mode){
   
var me = this;
   
var Text = window.XODText;
   
if (pattern !== '') {
        mode
= mode | me.docViewer.SearchMode.e_page_stop | me.docViewer.SearchMode.e_highlight;
       
if(me.currentPattern !== pattern){
            me
.startSearchPage = me.getCurrentPageNumber();
            me
.currentPattern = pattern;
            me
.searchMode = mode;
            me
.currentSearchedPages = 0;
            me
.resultFound = false;
            me
.searchEnd = false;
       
}
       
var callback = function(result){
           
if(result.resultCode === Text.ResultCode.e_done){
               
if(!me.searchEnd){
                    setTimeout
( function(){
                        me
.searchText(pattern, mode);
                   
}, 0);
               
}
           
}else if (result.resultCode === Text.ResultCode.e_page){
                me
.currentSearchedPages++;
               
if(me.currentSearchedPages === me.getPageCount()){
                    me
.searchEnd = true;
                    me
.currentPattern = '';
                   
if(me.resultFound){
                        alert
('Find reached the starting point of the search.');
                   
}else{
                        alert
('The specified text was not found.');
                   
}
               
}
           
}else if(result.resultCode === Text.ResultCode.e_found){
                me
.docViewer.displaySearchResult(result);
                me
.resultFound = true;
           
}
       
};
        me
.docViewer.textSearchInit(pattern, mode, false, callback);
   
}
}

Reply all
Reply to author
Forward
0 new messages