Can't change/jump to page
See original GitHub issueI’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:
- Created 5 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I found where my problem was. I wasn’t aware that
div
element with idviewerContainer
has to haveposition: absolute
so thatscrollIntoView
actually do something. The same goes for thediv
elementmainContainer
. 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 likePDFLinkService.
@timvandermeij Thank you for the help.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:Closing as answered unless more information is provided.