Performance issues when rendering large PDFs
See original GitHub issueThis might be a good question for pdf.js community itself but how does rendering large PDFs can be better handled with react-pdf?
pdf.js suggests not rendering more than 25 pages at a time: https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#allthepages
I even had to add this to my component to keep react from trying re-create the virtual DOM of the Document:
shouldComponentUpdate(nextProps, nextState) {
if(nextProps.file !== this.props.file
|| nextState.numPages !== this.state.numPages
|| nextState.width !== this.state.width){
return true
}
return false
}
The problem is that I also need to dynamically set the width of the document on user interacting so I can’t save myself from re-creating the virtual DOM after width changes, any way I can achieve this with your lib?
Issue Analytics
- State:
- Created 6 years ago
- Comments:58 (12 by maintainers)
Top Results From Across the Web
React-PDF Slow Performance with large PDF - Stack Overflow
If you keep rendering your pdf document multiple times you app performance will get affected and thereby decline.
Read more >What Contributes to Slow PDF Rendering? - PSPDFKit
Sometimes PDFs are broken. Lots of PDF software, including PSPDFKit, has support for recovering broken PDFs. One issue that can cause severe performance ......
Read more >How to Optimize PDFs for Accurate Rendering in PDF.js
A common cause of incorrect rendering is where documents embed a feature such as a PDF transparency, pattern or gradient not supported by...
Read more >582752 - Performance of PDF viewer with large files is bad
the final frame when the user stops scrolling a complex PDF. ... be half of the floor of the PDF render time and...
Read more >Guide to Evaluating PDF.js Rendering - PDFTron
Mozilla also recognized that rendering vector-based PDFs as large static images was ... off by default) contributing to performance and readability issues.
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 Free
Top 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
Hey everyone, I’d like to remind you that it was never React-PDF’s intention to provide the users with fully-fledged PDF reader. Instead, this is only a tool to make it. While I have a plan of creating React-PDF-based PDF reader, I’m far from it. Mozilla is working on it for years and they seem to never be done. I think it would go similar way 😉
There is some good news too, though. If I can suggest something,
onRenderSuccesscallback that you can define for<Page>components can be your powerful friend. You can use it to, for example, force pages to be rendered one by one:Of course you can do much more - add placeholders, check on scroll which pages need rendering, keep info on whether all pages so far were rendered… I believe in your creativity 😉 And if I can be of any help regarding API, please let me know!
I’ve had success with rendering with react-pdf together with react-window. The implementation below is inspired by the react-virtualized implementation by @michaeldzjap above and the description provided by @nikonet. It’s still a work in progress but so far it seems to perform well. Any suggestions to improve the implementation would be greatly appreciated.
One thing that concerns me, however: By caching all page dimensions on document load I would assume that you would loose the ability of pdfjs to load pages in chunks with range requests. Any thoughts on this?