PDFSinglePageViewer.scrollPageIntoView: X is not a valid pageNumber parameter.

Bug Report or Feature Request (mark with an x)
- [ ] Regression (a behavior that used to work and stopped working in a new release)
- [X ] Bug report -> please search issues before submitting
- [ ] Feature request
- [ ] Documentation issue or request

StackBlitz Reproduction
https://stackblitz.com/edit/ng2-pdf-viewer-bwntrw?devtoolsheight=33&file=src/app/app.component.ts

Two way page binding for always showing pdf last page is throwing console.error while executing correctly. ¿Why is the error showing and is there any way I could prevent this from happening? It seems scrollIntoView method somehow losses pdf pages array.

1 possible answer(s) on “PDFSinglePageViewer.scrollPageIntoView: X is not a valid pageNumber parameter.

  1. That’s not a bug. (after-load-complete) is called immediately after loading the document. At this point in time, the document hasn’t been rendered yet. So there are exactly zero pages. That’s why setting page="3" raises an error.

    You can add a timeout, or you can also implement (text-layer-rendered)="jumpToLastPage($event)" like so:

    export class AppComponent {
      src = "https://vadimdez.github.io/ng2-pdf-viewer/assets/pdf-test.pdf";
     
      pdfPage: number;
      lastPage: number;
      
      ...
      finishPdfLoad(event: PDFDocumentProxy) {
        this.lastPage = event.numPages;
      }
    
      jumpToLastPage(event: any) {
        this.pdfPage = this.lastPage;
      }
    }