Very Slow loading of some PDF files compared to other pdf viewers
First of all, thanks for this great multi-platform flutter package!
Pdfrx seems to have performance issues in some PDF files when compared to some other pdf-viewers, this is more noticeable with PDFs with many pages.
How to reproduce:
Download locally this publicly available pdf file: https://ia801408.us.archive.org/6/items/ERIC_ED619049/ED619049.pdf
On Android mid-range device:
- Open it with ReadEra -> Takes ~1 second for the viewer to open
- Open it with Firefox -> Takes ~1 second for the Firefox pdf viewer to open
And/OR On Linux:
- Open it with Chromium web browser -> takes ~ 1 second
- Open it with Firefox -> takes ~1 second
However, opening the same file for viewing with pdfrx on Flutter takes ~4 seconds on both Android and Linux (same Linux and Android hardware as above)
The code I used was the minimum example:
class _MainPageState extends State<MainPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Pdfrx example'),
),
body: PdfViewer.asset(
'assets/ED619049.pdf',
),
);
}
}
Environment I tested with
- Flutter version: 3.29.0
- pdfrx version: 1.1.5
- Platforms tested:
- Linux (Ubuntu 24.04)
- Android
- PDF details:
- Size: 30 MB
- Pages: 1574
What I tried
- I tried playing with different parameters found in pdf_viewer_params.dart, for example useAlternativeFitScaleAsMinScale, enableTextSelection, maxImageBytesCachedOnMemory, however, these changes did not yield any substantial improvements
- I tried opening the pdf using PdfPageView class, hoping to enhance performance by loading only 1 page. However, this approach did not reduce the delay, opening the pdf file for viewing take the same amount of time.
The pdf file above is an example that illustrates the issue, but I noticed this pattern with other PDF files too
Is there a known solution for this problem?
Because of the current design of pdfrx, when it opens a new document, it firstly loads all the pages to know whole document structure. And it may be the cause of the slowness.
Other PDF viewers just loads only the first page (or anyway several pages only) to reduce the time to show the first page.
Basically, this is just a design dicision and it's not difficult to implement the second approach on pdfrx but it breaks compatibility with the older versions...
Anyway, I'll consider more about the dicision again.
Basically, this is just a design dicision and it's not difficult to implement the second approach on pdfrx but it breaks compatibility with the older versions...
I see, this type of feature would take the form of a boolean parameter called something like lazyLoading ?
No, it breaks lower layer API compatibility and could not co-exist with the existing codes.
BTW, even Flutter framework takes such kind of incompatibilities on every featured release. So it can be acceptable to introduce such level of breaking changes I guess.
Thanks for getting back on this issue.
My two cents on this: The benefits of improving load times of big PDFs through this feature would out-weight the drawbacks of breaking backward compatibility with pre-existing codes that use previous versions of pdfrx
Yes, I believe so. OK, I'll try to introduce some asynchronous loading mechanism.
Yes, I believe so. OK, I'll try to introduce some asynchronous loading mechanism.
thank you so much! my users load pdfs with over 1500 pages. takes 4-5 seconds to load. I appreciate your work! Many thanks!
the same as me, it takes around 10 seconds to load large pdf. great package btw, thanks!
https://github.com/espresso3389/pdfrx/issues/393#issuecomment-2961780681
[@FeofanGreek] In my opinion, may be possible do two stage loading? This is only my thing. On first stage we can calculate pages, sizes, may be some thing more "quick" variables. On the second stage do scaning document for search, draw annotations and bookmarks... Yes, I totally agree to your opinion. The approach may:
Delay loading of PdfDocument.pages Certain apps depends on pdfrx does not assume pages will change after first loading We should need some flags to activate the delay loading?? getPages function (async version)? Delay loading notification callback (on pages change) PdfViewer(initialPageNumber) may wait for the page being loaded Meaning of isReady Anyway, it apparently breaks "some" compatibility with the existing codes... Should we do major upgrade for that?
I'm working on lazy_page_load branch now.
pdfrx 1.2.0 (6964170ee4557b907e148acfba9fab7084c8e3ca) contains the changes to support lazy loading of the pages.
But the release also contains breaking changes that removes supports of Pdf.js.
Anyway, try the latest version!
pdfrx 1.2.0 (6964170) contains the changes to support lazy loading of the pages.
But the release also contains breaking changes that removes supports of Pdf.js.
Anyway, try the latest version!
works great! thank you!