Navigation to the specific page when searching text in PDF viewer

Dear Sir,

How can I allow the pdf viewer jump to the specific page after search?

The  pdfViewer.textSearchModule.searchText(text) function is working perfectly and I can see the search text is being highlighted but how can I let the viewer jump to that page?

I try to use   pdfViewer.navigation.goToLastPage() and   pdfViewer.navigation.goToPage(pageno); but it always go back to p


function loadPdf() {

        var pdfViewer = document.getElementById('pdfviewer').ej2_instances[0];

        var filename = document.getElementById('txtfilename').value;

        var text = document.getElementById('txtsearchstring').value;

         ej.pdfviewer.PdfViewer.Inject(ej.pdfviewer.TextSearch,ej.pdfviewer.navigation);

        pdfViewer.serviceUrl = '/api/PdfViewer';

        pdfViewer.load(filename, null);

        pdfViewer.textSearchModule.searchText(text);

        pdfViewer.navigation.goToLastPage();

    }


Regards,

WK


3 Replies

CW Chua Wei Kiat January 13, 2022 08:26 AM UTC

Besides, does DocumentEditor available for these two functions as well?
If yes, could you please provide me with the command (search and navigate to the target page)?



SK Shamini Kiruba Sobers Syncfusion Team January 14, 2022 12:21 PM UTC

Hi Chua, 

You can use the same functions “pdfViewer.navigation.goToPage(pageno);” and “pdfViewer.navigation.goToLastPage();” to jump to the specified page and to the last page respectively. We suggest you avoid calling the load method within the function to load the document again as this causes the issue. The document can be loaded during the component initialization itself as in the below code. 

<button onclick="loadPdf()">Load PDF</button> 
 
<ejs-pdfviewer id="pdfviewer" style="height:600px" serviceUrl="/api/PdfViewer" documentPath="PDF_Succinctly.pdf" enableNavigation="true"></ejs-pdfviewer> 
 
<script> 
    function loadPdf() { 
 
        var pdfViewer = document.getElementById('pdfviewer').ej2_instances[0]; 
 
        var text = "PDF"; 
 
        pdfViewer.textSearchModule.searchText(text); 
 
        //pdfViewer.navigation.goToLastPage(); 
 
        pdfViewer.navigation.goToPage(12); 
 
    } 
</script> 

Kindly refer to the below working sample and revert to us if any queries. 

We have forwarded the Document Editor related query to the concerned team. We will update the details on January 17th, 2022

Regards, 
Shamini 



SK Shamini Kiruba Sobers Syncfusion Team January 17, 2022 07:10 AM UTC

Hi Chua, 
In Document Editor, you can use find API to search to the specific text and scrollToPage API to navigate to specific page number. 
Code snippet:  
documenteditor.search.find('Some text', 'None');  
//// Give page number in parameter  
documenteditor.scrollToPage(2);  
  
Documentation: 
 
 
Regards, 
Shamini 


Loader.
Up arrow icon