wojtekmaj / react-pdf

Display PDFs in your React app as easily as if they were images.
https://projects.wojtekmaj.pl/react-pdf
MIT License
9.01k stars 861 forks source link

onLoadProgress total is NaN when fetching a pdf from a url #1752

Open shihabdider opened 3 months ago

shihabdider commented 3 months ago

Before you start - checklist

Description

I am trying to create a progress bar which displays while the pdf is loading. When fetching a large pdf from a url, the total attribute of the onLoadProgress callback is NaN until the very end, when the pdf is fully loaded (which defeats the purpose of a loading bar).

I suspect this is not really a bug, but I'm wondering how/whether it's possible to get the total by some other means. Otherwise, I can just use a spinning wheel, but the progress bar is obviously better.

Steps to reproduce

Try to load a large pdf by supplying its url to the file prop. Then log the onLoadProgress callback's total attribute.

Expected behavior

Ideally it should compute the total for the fetched document somehow (perhaps using the headers?)

Actual behavior

It set as NaN until the very end. loaded works just fine.

Additional information

No response

Environment

github-actions[bot] commented 1 week ago

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 14 days.