react-pdf-viewer icon indicating copy to clipboard operation
react-pdf-viewer copied to clipboard

Programmatically scroll/change page.

Open handofthecode opened this issue 3 years ago • 1 comments

Is there a way to programmatically scroll the document?

I would like to be able to change pages without having to re-render the component with a new initialPage number.

handofthecode avatar Mar 15 '21 18:03 handofthecode

Hey @handofthecode , I managed to get this done using pageNavigationPlugin:

  import { pageNavigationPlugin } from '@react-pdf-viewer/page-navigation';

  ...

  const pageNavigationPluginInstance = pageNavigationPlugin();

  const { jumpToPage } = pageNavigationPluginInstance;

Was able to get the number of pages using this:

  function onDocumentLoadSuccess(e: DocumentLoadEvent) {
    setNumPages(e.doc.numPages);
  }

 ...

  <Viewer
            ...
            onDocumentLoad={onDocumentLoadSuccess}
          />

adamthewan avatar Jun 25 '21 16:06 adamthewan