-
Notifications
You must be signed in to change notification settings - Fork 10.3k
PDF rendering is quite slow with some PDFs, compared to other viewers #14652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
That PDF document contains a huge amount of path rendering operators, which likely explains why this is a bit slow since that's something that's not entirely easy to optimize (and it thus looks a tiny bit similar to e.g. issue #10565). |
@Snuffleupagus how do you check the number of paths in a PDF? Also, any idea how to reduce that number, without visually affecting anything? I mean offline solutions, of course, not realtime ones. Although those would be the best, but I believe those are just too complicated, as you mentioned. |
I didn't bother counting, but simply eyeballed what's in the /Contents-streams and noticed a very large number of path operators. (Hence I figured that it may be relevant here, since we've seen before that it can lead to poor performance.)
Unfortunately we cannot help with PDF creation here, since that's not really something that the PDF.js library does; hence the only information we can provide is https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#optimize
Please note that my comment was only regarding the PDF.js library itself, since I cannot see any simple solution here. |
@Snuffleupagus where is |
@soadzoor This refers to the built-in structure of the PDF file. You can open the file with a PDF browser, for example https://brendandahl.github.io/pdf.js.utils/browser/, to see the inner structure of the PDF file. In the tree there is also a |
@timvandermeij Hm, but on the linked page, I can only see entries like
How do I check how many The question is: how can I retrieve that information? |
You'd essentially have to manually instrument the code, if you want a fully accurate number (w.r.t. the PDF document itself), since no such functionality is provided (there's no general use-case that warrants adding such a feature). Although, I suppose that it's also possible to use the Lines 1537 to 1546 in ee39499
Lines 1212 to 1219 in ee39499
|
Thanks! I played around with this, and it seems the PDF file above has That doesn't seem like a lot. For example the following PDF has more than 3 times as many path rendering operators ( Or this one has more than 1.2 million path rendering operators, yet it still seems to be faster to render than the original one in the first post: So I don't think there's a linear correlation between the number of path rendering operators and performance. I think there's more to this 🤔 |
Note that you've underestimated the actual number by at least one order of magnitude, since only counting |
you can try pdf slice loading, very fast: Introduces the address |
It renders in about 3 seconds on Windows, and one can see that something is happening. My PC is from 2017 but with lots of memory. I don't see this as a performance problem at all.
this would take longer than rendering this PDF itself. |
Attach (recommended) or Link to PDF file here:
Floor2.pdf
Configuration:
Steps to reproduce the problem:
What is the expected behavior? (add screenshot)
It should be quicker. I tried opening the same PDF with "preview" on mac, and with chrome, and they both render the PDF much-much faster, without any noticable loading/hanging.
What went wrong? (add screenshot)
It takes quite a while to load up/render the PDF, and then when I start zooming in and out, it often just turns white, and it hangs for 5-10 seconds before I can see something again.
By the way, I noticed this issue in a complex project, where we use the pdf.js javascript API to render certain parts of the PDF (with a defined viewbox), but it's much easier to reproduce the issue with the official PDF viewer. I sometimes had performance issues before, but in those cases other viewers weren't really any better for those PDFs. With this particular PDF, other viewers/renderers can outperform PDF.js by a lot.
So maybe someone here can find the reason behind it, and even fix it.
The text was updated successfully, but these errors were encountered: