Coder Social home page Coder Social logo

Comments (10)

mvanlonden avatar mvanlonden commented on June 14, 2024 5

Just figured it out! UI.renderPage is getting called multiple times on some pages and causes that strange effect. By tracking the page numbers that have been rendered in an array and checking if a page has been rendered before calling UI.renderPage will remove the issue.

from pdf-annotate.js.

roypardi avatar roypardi commented on June 14, 2024 5

I encountered this too and am testing the "array" suggestion above. Seems to work.

// Render stuff
let NUM_PAGES = 0;
let renderedPages = [];
let okToRender = false;
document.getElementById('content-wrapper').addEventListener('scroll', function (e) {
  let visiblePageNum = Math.round(e.target.scrollTop / PAGE_HEIGHT) + 1;
  let visiblePage = document.querySelector(`.page[data-page-number="${visiblePageNum}"][data-loaded="false"]`);

  console.log('pages', visiblePageNum, renderedPages.indexOf(visiblePageNum));

  if (renderedPages.indexOf(visiblePageNum) == -1){
    okToRender = true;
    renderedPages.push(visiblePageNum);
  } else {
    okToRender = false;
  }

  if (visiblePage && okToRender) {
    setTimeout(function () {
      UI.renderPage(visiblePageNum, RENDER_OPTIONS);
    });
  }
});

from pdf-annotate.js.

mvanlonden avatar mvanlonden commented on June 14, 2024

Any luck with this @ghedwards?

from pdf-annotate.js.

ghedwards avatar ghedwards commented on June 14, 2024

Sort of.. I ended up building our own solution entirely using PDFJS, unfortunately I probably can't share it on here. Happy to have a chat about it privately if it's something you're looking for, send me an email or a Hangouts chat request.

from pdf-annotate.js.

stoberov avatar stoberov commented on June 14, 2024

Hi @mvanlonden , thanks for the hint! I couldn't solve it with an array - instead, I made sure scrolling doesn't trigger more than one event by adding a timeout:

var timeout;

   document.getElementById('content-wrapper').addEventListener('scroll', function (e) {
    clearTimeout(timeout);

    timeout = setTimeout(function() {
        var visiblePageNum = Math.round(e.target.scrollTop / PAGE_HEIGHT) + 1;
        var visiblePage = document.querySelector('.page[data-page-number="' + visiblePageNum + '"][data-loaded="false"]');

        if (visiblePage) {
            setTimeout(function () {
                UI.renderPage(visiblePageNum, RENDER_OPTIONS);
            });
        }
    }, 50);
});

from pdf-annotate.js.

geocine avatar geocine commented on June 14, 2024

Thanks guys! @roypardi do you want to do a pull request. I tried your code and works.

from pdf-annotate.js.

roypardi avatar roypardi commented on June 14, 2024

I don't have a fork of this – I was just messing with a one-off download, so you will have to add it directly.

from pdf-annotate.js.

patryksosinski avatar patryksosinski commented on June 14, 2024

You also need to remember to clear the renderedPages array when you change scale or rotate as the pages won't be re-rendered.

from pdf-annotate.js.

AP-Nothize avatar AP-Nothize commented on June 14, 2024

Fixed in #57. But @patryksosinski 's point which is a good point is not catered yet!

from pdf-annotate.js.

ashishdotsquares avatar ashishdotsquares commented on June 14, 2024

Hi guys,

I have resolvedd this issues from my end. Please have a look below mentioned changes into my code (index.js) on Line number 140.

		var NUM_PAGES = 0;
		var timeout;
		document.getElementById('content-wrapper').addEventListener('scroll', function(e) {
				clearTimeout(timeout);
				timeout = setTimeout(function() {
					var visiblePageNum = Math.round(e.target.scrollTop / PAGE_HEIGHT) + 1;
					var visiblePage = document.querySelector('.page[data-page-number="' + visiblePageNum + '"][data-loaded="false"]');
					if (visiblePage) {
							setTimeout(function() {
									UI.renderPage(visiblePageNum, RENDER_OPTIONS);
							});
					}
				}, 50);
		});

from pdf-annotate.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.