Moderately large PDF files crashing on tablet devices
See original GitHub issueBug 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
Issue: Moderately large PDF files almost always crash on tablet devices. I have tested this on a normal chrome browser and chromium web-view for android as well.
What I observed: Your viewer seems to paint all the pages to the DOM at once as soon as the PDF loads. This happens regardless of whether a given page is visible in the DOM or not. On low powered android devices like a tablet, this causes a graphics memory leak leading to all the apps crashing due to low available heap memory.
I fired up this sample implementation of PDFjs from Mozilla that loads a large PDF file: https://mozilla.github.io/pdf.js/web/viewer.html
If you poke around in the DOM you can see how the canvas layer and the text layer are not rendered for all pages initially. Its only when you scroll towards those pages that these get added as nodes.
I tried loading this page on the same tablet and it never seems to crash.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Have you tested if the same thing happens here https://vadimdez.github.io/ng2-pdf-viewer/ ?
https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#i-want-to-render-all-100-pages-in-a-document-at-a-high-resolution-is-it-a-good-idea
I want to render all 100 pages in a document at a high resolution. Is it a good idea? Not really. You can count yourself: a letter page size is 816⨉1056px at 96DPI (and if you have a HiDPI display, multiply each dimension by window.devicePixelRatio, e.g., 2), so you will need a canvas that takes up 816⨉1056⨉4 = 3,446,784 bytes (don’t forget to multiply that by e.g., 2⨉2 = 4 if it’s a HiDPI display). This requires you to allocate 3.5Mb (or 14Mb) per page. You need a decent amount of memory to hold the 100 canvases, and it does not count the time that is spent on rendering them.
The demo viewer creates, renders, and holds canvases only for visible pages to reduce the amount of used memory. Our recommendation is to create and render only visible pages.