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.

Moderately large PDF files crashing on tablet devices

See original GitHub issue
Bug 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.

image

I tried loading this page on the same tablet and it never seems to crash.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
VadimDezcommented, May 19, 2021

Have you tested if the same thing happens here https://vadimdez.github.io/ng2-pdf-viewer/ ?

1reaction
ashish-koshycommented, Mar 20, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Having trouble with PDF reader apps crashing with larger-size ...
That's a moderately large file. Try the trick where you print just the pages you need to PDF. Open it in Preview, go...
Read more >
App keeps crashing - Adobe Support Community - 11361265
Solved: When I open Acrobat for samsung app it keeps crashing and wont open. It is doing this when I go to open...
Read more >
Files app pdf crash - Apple Community
PDFs of any size of maybe 5 to 10 pages or more are constantly crashing and just turning off and then rarely well...
Read more >
Limitations on opening pdf file in Android - Stack Overflow
Opening good PDF on APP of the company that PDFs crash ~~> OK. EDIT. I have noticed that I was using http:// protocol...
Read more >
Large PDF files crash my PC! - Acrobat Answers
When working with large PDF files of 30000 pages or more my computer crashes several times a day (may also be running programs...
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