If I understand your problem well, I may have a solution. When I clicked too quickly on the buttons of the previous or next, there was no time for updating on the canvas, and the two (or more) pages on which it was drawn were unreadable.
To solve the problem, I use the following code:
var stop = false; function goPrevious() { if (pageNum > 1 && !stop) { stop = true; pageNum--; renderPage(pageNum); } } function goNext() { if (pageNum < pdfDoc.numPages && !stop) { stop = true; pageNum++; renderPage(pageNum); } }
I also changed the rendering function in the pdf.js file:
render: function PDFPageProxy_render(params) { this.renderInProgress = true; var promise = new Promise(); var stats = this.stats; stats.time('Overall'); // If there is no displayReadyPromise yet, then the operatorList was never // requested before. Make the request and create the promise. if (!this.displayReadyPromise) { this.displayReadyPromise = new Promise(); this.destroyed = false; this.stats.time('Page Request'); this.transport.messageHandler.send('RenderPageRequest', { pageIndex: this.pageNumber - 1 }); } var self = this; function complete(error) { self.renderInProgress = false; stop = false; if (self.destroyed || self.cleanupAfterRender) { delete self.displayReadyPromise; delete self.operatorList; self.objs.clear(); } if (error) promise.reject(error); else promise.resolve(); } var continueCallback = params.continueCallback; //etc.
(in my pdf.js file, this is between lines 2563 and 2596).
As a result, a new page will not be drawn until the previous page is completely drawn, even if you click very quickly on the previous / next buttons!
Another solution might be to undo the previous picture:
function renderPage(num) { pdfDoc.getPage(num).then(function(page) {
I hope this helps you and sorry for my English;) Have a nice day
source share