question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't change/jump to page

See original GitHub issue

I’m using this library with React to render the whole pdf document and also have the function to go to particular page. The strange thing is that I can’t jump to page only when I’m rendering my whole document with new pdfjsViewer.PDFViewer , but when I’m using new pdfjsViewer.PDFSinglePageViewer for rendering just one page at the time I can normally jump to page and implement all other functions.

This is some of my code:

import * as pdfWorker from 'pdfjs-dist/build/pdf.worker'
import PdfJsLib from 'pdfjs-dist';
import 'pdfjs-dist/web/pdf_viewer.css';
import * as pdfjsViewer from 'pdfjs-dist/web/pdf_viewer';

...

componentDidMount() {
        let container = this.viewerContainer.current;
        let viewer = this.viewer.current;

        PdfJsLib.GlobalWorkerOptions.workerSrc = pdfWorker;
        PdfJsLib.getDocument(this.props.file).then((pdf) => {

            this.setState({numPages: pdf.numPages});

            this.pdfLinkService = new pdfjsViewer.PDFLinkService();

            this.pdfFindController = new pdfjsViewer.PDFFindController({
                linkService: this.pdfLinkService,
            });

            this.pdfViewer = new pdfjsViewer.PDFViewer({
                 container,
                 viewer,
                 linkService: this.pdfLinkService,
                 findController: this.pdfFindController
            });
            this.pdfLinkService.setViewer(this.pdfViewer);

            this.pdfViewer.setDocument(pdf);
            this.pdfLinkService.setDocument(pdf, null);

            this.pdfViewer.onePageRendered.then(() => {
                 pdf.getOutline().then((outline) => {
                     this.outline = outline || null;

                     if (!outline) {
                        return;
                     }
                     this.setState({bookmarkItems: outline});
            });
       });
   });
}



...

onNextPageClick = () => {
    if(this.state.numPages > this.state.pageNumber) {
        this.setState({pageNumber: this.state.pageNumber + 1});
        this.setState({pageNumberInput: this.state.pageNumber + 1});

        this.pdfViewer.currentPageNumber++;
    }
}
onPreviousPageClick = () => {
    if(this.state.pageNumber > 1) {
        this.setState({pageNumber: this.state.pageNumber - 1});
        this.setState({pageNumberInput: this.state.pageNumber - 1});

        this.pdfViewer.currentPageNumber--;
    }
}

...

render() {
    return(

        ...

        <div className="splitToolbarButton hiddenSmallView">
            <button className="toolbarButton pageUp" title="Previous Page" id="previous" tabIndex="13" data-l10n-id="previous" onClick={this.onPreviousPageClick}>
            <span data-l10n-id="previous_label">Previous</span>
            </button>
         <div className="splitToolbarButtonSeparator" />
            <button className="toolbarButton pageDown" title="Next Page" id="next" tabIndex="14" data-l10n-id="next" onClick={this.onNextPageClick}>
             <span data-l10n-id="next_label">Next</span>
            </button>
        </div>

         ...

        <div id="viewerContainer" ref={this.viewerContainer}>
            <div id="viewer" ref={this.viewer} className="pdfViewer" />
        </div>
    )
}

Is there anything that I’m doing wrong here or am I missing something?

Configuration:

  • Web browser and its version: Chrome 71.0.3578.98
  • Operating system and its version: Windows 10
  • PDF.js version: 2.0.489

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
RudmanMariocommented, Dec 27, 2018

I found where my problem was. I wasn’t aware that div element with id viewerContainer has to have position: absolute so that scrollIntoView actually do something. The same goes for the div element mainContainer. Of course it make sense now but I was looking at the wrong places all the time thinking it has to do something with react or services like PDFLinkService. @timvandermeij Thank you for the help.

6reactions
timvandermeijcommented, Dec 25, 2018

From the description it’s not clear what you mean by “jumping to a page”. If you mean changing the page, you can use the PDFViewer.currentPageNumber setter (https://github.com/mozilla/pdf.js/blob/master/web/base_viewer.js#L207). Moreover, as outlined in https://github.com/mozilla/pdf.js/blob/master/.github/CONTRIBUTING.md, just code snippets won’t help to debug the issue:

If this does not help, please prepare a short well-documented example that demonstrates the problem and make it accessible online on your website, JS Bin, GitHub, etc. before opening a new issue or contacting us on the IRC channel – keep in mind that just code snippets won’t help us troubleshoot the problem.

Closing as answered unless more information is provided.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How Do I Stop Text From Jumping to the Next Page in Word
If your text is jumping to a new page, skipping half a page then you probably need to clear some pagination settings.
Read more >
Content Jumping (and How To Avoid It) | CSS-Tricks
Few things are as annoying on the web as having the page layout unexpectedly change or shift while you're trying to view or...
Read more >
Text jumps to the next page? - Microsoft Community
Right-click on the paragraph at the top of the second page and select Paragraph. On the Line and Page Breaks tab of the...
Read more >
How to prevent a click on a '#' link from jumping to top of page?
Just use "#/" instead of "#" and the page won't jump. Share.
Read more >
Jumping to a Specific Page - Word Ribbon Tips
Word allows you to move the insertion point to any page in your document by using the Go To command. To take advantage...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found