Ng2-pdf-viewer: PDFSinglePageViewer.scrollPageIntoView: X is not a valid pageNumber parameter.

Created on 18 Dec 2020  路  2Comments  路  Source: VadimDez/ng2-pdf-viewer

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.

Most helpful comment

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;
  }
}

All 2 comments

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;
  }
}

Thank you so much for the clarification. Worked like a charm.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

roginneil picture roginneil  路  3Comments

Gianlu82b19 picture Gianlu82b19  路  4Comments

manojbhardwaj picture manojbhardwaj  路  7Comments

fncamm picture fncamm  路  4Comments

VadimDez picture VadimDez  路  5Comments