Skip to content

Pages rendered upside down when using continueCallback #2923

@benbro

Description

@benbro

In the example with the prev/next page controls, if you click on the Next button too fast it'll render pages one on top of the other.
I've modified the example to use the continueCallback function but now when clicking on the button fast it sometimes renders the page upside down or with a wrong scale.

http://jsbin.com/pdfjs-prevnext-v2/1939/edit

var pdfDoc = null,
    pageNum = 1,
    scale = 2,
    canvas = document.getElementById('the-canvas'),
    ctx = canvas.getContext('2d'),
    timestamp;

//
// Get page info from document, resize canvas accordingly, and render page
//
function renderPage(num) {
  // Using promise to fetch the page
  pdfDoc.getPage(num).then(function(page) {
    var viewport = page.getViewport(scale);
    canvas.height = viewport.height;
    canvas.width = viewport.width;

    // Render PDF page into canvas context
    var pageTimestamp = new Date().getTime();
    timestamp = pageTimestamp;
    var renderContext = {
      canvasContext: ctx,
      viewport: viewport,
      continueCallback: function(cont) {
        if(timestamp != pageTimestamp) {
          return;
        }
        cont();
      }
    };
    page.render(renderContext);
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions