Instant Display of Large PDF Files: Modifying pdf-js Components for Background Downloading #313
Replies: 7 comments 1 reply
-
Hi @rocheston, thanks for the question. This will be tricky for a few reasons, one of them being that the PDF app is not very efficient when loading large PDF's currently, even once it has the entire file local. I had planned at some point to add lazy loading to how it loads the pages because as it is now it can get quite slow when it's many pages. As for loading in the background or via streaming, that is another complexity as I am not sure if PDF's can be loaded intermittently, and if they can I imagine it would be something pdf.js would need to support. I don't know enough about PDF's to even say what a "linearized" means in the context of being able to load it this way. I will add this as a feature request and in the mean time if you find anything in the pdf.js docs/repo about how to do this please post it here and I can give further advice on how to integrate the feature. |
Beta Was this translation helpful? Give feedback.
-
I see a bit about linearized PDF's so maybe it's possible. Do you have an example link of a linearized PDF I could use for testing? |
Beta Was this translation helpful? Give feedback.
-
I played with this a bit last night and made some progress in lazy loading, but ran into trouble with reliability of intersection observer. Do you have a linearized PDF @rocheston? Also do you have it un-linearized so I can compare? I think the way the code is, the file system will need to read the file totally, but we can avoid loading every page in advance which is how it is now. |
Beta Was this translation helpful? Give feedback.
-
I made an attempt, but unfortunately, it wasn't successful. The PDF is completely downloaded to determine the total number of pages. The issue seems to stem from PDF/JS. I tried these settings. Doesn't seem to work. To create linearized PDF in mac, open a PDF in Preview --> Export to PDF (Select Linearized in the save option). |
Beta Was this translation helpful? Give feedback.
-
Here is the linearized PDF. https://rcce.cc/SQCaX |
Beta Was this translation helpful? Give feedback.
-
I've added some rendering async logic. |
Beta Was this translation helpful? Give feedback.
-
Amazing! It's functioning perfectly now. The PDF loads seamlessly. A huge thank you, Dustin, for your incredible assistance and support. 🙏 |
Beta Was this translation helpful? Give feedback.
-
I have PDF files exceeding 200MB, and pdf-js requires downloading the entire file before displaying the first page, which is time-consuming. How can I modify components/app/pdf to instantly display the page while simultaneously downloading the file in the background?
My pdf files are linearized.
Beta Was this translation helpful? Give feedback.
All reactions