jkgenser / react-pdf-headless

MIT License
23 stars 1 forks source link

Changing zoom level causes scroll position to change #10

Open rschev opened 3 months ago

rschev commented 3 months ago

When you're scrolled far into a long PDF and change the zoom level, the viewer jumps to a different page. This is because the browser just remembers how many pixels deep you've scrolled. After changing zoom levels, your pages are taller or shorter, so this changes the place in the document that corresponds to that distance scrolled.

I've run into this same issue in my own pdf reader project and fixed it by tracking how far we are in the document as a percentage of the total document height. Then after changing the zoom level, we have a new total document height, and we can use the percentage to find the new position in pixels that matches where we were in the document.

You can see the particular bit about recalculating the position here. Feel free to incorporate it into this project.

jkgenser commented 1 day ago

@rschev thanks for this bug report! We just experienced this in our app so i'm going to get it fixed.