Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to scroll to page? #63

Closed
akarabach opened this issue Mar 3, 2017 · 13 comments
Closed

How to scroll to page? #63

akarabach opened this issue Mar 3, 2017 · 13 comments
Assignees
Milestone

Comments

@akarabach
Copy link

version: ^1.0.2

<pdf-viewer [src]="assets/test.pdf"
            [page]="'3'"
            [original-size]="true"
            [show-all]="true"
            style="display: block;">
</pdf-viewer>

This code doesn't work. How i can scroll to 3 page in pdf file ?

@VadimDez
Copy link
Owner

VadimDez commented Mar 3, 2017

The functionality will be available in 2.0.0.
For now you can use [(page)]="page" with [show-all]="true". Or you can always implement your own scrollTo with js.

@akarabach
Copy link
Author

akarabach commented Mar 3, 2017

For now you can use [(page)]="page" with [show-all]="true".

doesn't work

@VadimDez
Copy link
Owner

You can use [stick-to-page]="true" available since 2.0.0. Closing.

@VadimDez VadimDez reopened this Jan 10, 2018
@VadimDez VadimDez self-assigned this Jan 10, 2018
@VadimDez VadimDez added this to the 3.0.8 milestone Jan 10, 2018
VadimDez added a commit that referenced this issue Jan 10, 2018
Closes #63 made "pdfViewer" public, added example method to scroll to a page
@VadimDez
Copy link
Owner

Now you can scroll to a page with the following code, add this to your component that uses pdf-viewer component

// define view child
@ViewChild(PdfViewerComponent) private pdfComponent: PdfViewerComponent;

// ...

scrollToPage(page: number) {
  this.pdfComponent.pdfViewer.scrollPageIntoView({
    pageNumber: page
  });
}

and then use it

scrollToPage(3);

@metanav
Copy link

metanav commented Jan 19, 2018

How can I import PdfViewerComponent, which package?

@VadimDez
Copy link
Owner

@metanav can you try?

import { PdfViewerComponent } from 'ng2-pdf-viewer/dist/pdf-viewer.component.js';

@abbasshujah
Copy link

It is not working for me if anyone has made it work can you post an example

@akarabach
Copy link
Author

@abbasshujah Memory leaks in this lib, don't use it for large files. See https://github.com/VadimDez/ng2-pdf-viewer/issues/220

Try to use pdfjs-dist and typings for it @types/pdf. I don't remember why we didn't use this library, but pdfjs works perfect.

@abbasshujah
Copy link

abbasshujah commented Jun 20, 2018 via email

@CC2013
Copy link

CC2013 commented Dec 27, 2018

Now you can scroll to a page with the following code, add this to your component that uses pdf-viewer component

// define view child
@ViewChild(PdfViewerComponent) private pdfComponent: PdfViewerComponent;

// ...

scrollToPage(page: number) {
  this.pdfComponent.pdfViewer.scrollPageIntoView({
    pageNumber: page
  });
}

and then use it

scrollToPage(3);

I tried this in my project, but it didn't work. Any other ideas that I can show all pages and also can use pagination to guide which page I want?

@ParagBadala
Copy link

Scroll is not working for me when i used it in my project please help me in this

@pumbhadianilesh
Copy link

VadimDez

I need to scroll to particular position within a single page programmatically (scroll to left or right and top or Bottom).
Please help me in that regard.

Thanks in Advance

@cascesme
Copy link

cascesme commented Sep 13, 2022

I solved this issue by creating my own implementation to scroll to view.

private scrollToPage(page: number): void {
        const scroller = $(`div.page[data-page-number|=${page}]`)[0];
        if (scroller !== undefined && page > 1) {
            scroller.scrollIntoView({ behavior: 'smooth', block: 'center' });
        }
}

This should be executed (after-load-complete)="setTimeout(()=>scrollToPage(page), 50)"

Even if this is marked as solved by the library I can't get it to work the normal way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants