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

Scroll to page

Open laaragm opened this issue 1 year ago • 7 comments

Hi! Is it possible to scroll to a particular page given a certain document? Is it something you'd consider for the future? Thanks.

laaragm avatar Sep 10 '23 21:09 laaragm

it could be very helpful to include this function!

zhongshuai-cao avatar Oct 04 '23 20:10 zhongshuai-cao

+1 on this

karam-khanna avatar Oct 12 '23 21:10 karam-khanna

@cyntler can you assign this to me, I can set default page for pdf

VAJRESH avatar Oct 20 '23 06:10 VAJRESH

Hello @VAJRESH Do you know when will be included that feature ? Thanks

For anybody coming here, this is a way I have found to solve this problem by selecting the html tag of the good page and scrolling to there and adding some wait time to let the doc to load

      useEffect(() => {

        const handleSetDocs = (() => {

               // Delay scrolling until the element is likely to be loaded
                const timer = setTimeout(() => {
                    
                    const element = document.getElementById("lolo");
                    console.log('element\n', element);
                    const elementsArray = document.querySelectorAll('.sc-bjfHPd.kQleml');
                    if (elementsArray.length > 0) {
                        console.log('elementsArray\n', elementsArray);
                        const ElementPage = elementsArray[(props.pageToDisplay - 1)].getBoundingClientRect();
                        if (element) {
                          console.log('c2: ', ElementPage.top);
                            element.scrollTo(0, ElementPage.top )
                          }
                    }
                    
                }, 2500); // Delay for X milliseconds (1 second)
            
                return () => clearTimeout(timer); // Cleanup the timer

            })

        handleSetDocs();


    }, [props.pageToDisplay])

mathieugruson avatar Feb 06 '24 13:02 mathieugruson

Hi everyone, just checking if anyone have a better solution to this issue? The above useEffect code is buggy for me as it requires the document to be loaded before the scrolling happens, occasionally a bug occurs where the scrolling causes the document to scroll to a random page. Thanks in advance!

angeal-chw avatar Jul 09 '24 11:07 angeal-chw

I'm not getting this code to work. When I log what's inside const element it says null. What Id should I pick there ?

When i pick react-doc-viewer as id, I get the following console output, but no scrolling is taking place ... image

Support for scroll to page would be a huge improvement, please implement it in the package...

jooskesters avatar Aug 22 '24 13:08 jooskesters