PDF Viewer

Can I use text highlighting and navigate through pages via API, without using the user interface?


1 Reply

CK Chinnamunia Karthik Chinna Thambi Syncfusion Team September 28, 2023 01:27 PM UTC

Please find the details.

 

For text highlighting

You can highlight text in the code-behind by utilizing the #addannotation method. We've included a code snippet and a sample to demonstrate this functionality.

 

Code snippet:

 

 

    function highlight() {

        var viewer = document.getElementById('container').ej2_instances[0];

        viewer.annotation.addAnnotation("Highlight", {

          bounds: [{x: 97, y: 610, width: 350, height: 14}],

          pageNumber: 1

        });

    }


Sample: https://stackblitz.com/edit/react-qsnfmf-ilcbve?file=index.js,index.html,package.json

For navigate through pages

You can navigate through pages using the provided APIs.

 

  • To move to the next page, you can use the "goToNextPage" API.
  • For the previous page, utilize the "goToPreviousPage" API.
  • To go to a specific page, you can make use of the "goToPage" API, by specifying the page number as a parameter.

 

Below, you'll find a code snippet and a sample demonstrating these actions.

 

Code snippet:

 

 

    function previousPage() {

        var viewer = document.getElementById('container').ej2_instances[0];

        viewer.navigation.goToPreviousPage();

    }

 

    function nextPage() {

        var viewer = document.getElementById('container').ej2_instances[0];

        viewer.navigation.goToNextPage();

    }

 

    function goToPage3() {

        var viewer = document.getElementById('container').ej2_instances[0];

        viewer.navigation.goToPage(3); // Navigates to the page 3

    }


Sample: https://stackblitz.com/edit/react-qsnfmf-ilcbve?file=index.js,index.html,package.json


Loader.
Up arrow icon