wonday / react-native-pdf

A <Pdf /> component for react-native
MIT License
1.6k stars 549 forks source link

Loader (Progress Bar) is not working when requesting PDF from API #413

Open ali-hellani opened 4 years ago

ali-hellani commented 4 years ago

What react-native version are you using? ----- 0.61.4

What react-native-pdf version are you using? ----- 6.0.0

What platform does your issue occur on? (android/ios/both) ---- ios

Describe your issue as precisely as possible : Loader (Progress Bar) is not working properly when requesting a PDF from API, and the percentage values in onLoadProgress are in negative form

Join a screenshot or video of the problem on the simulator or device? react-native-pdf-api-issue

Show us the code you are using?

renderPdf = () => {
    const source = {
      uri: this.state.document.url,
      cache: false,
      expiration: 0,
      headers: Util.getAuthorization(),
      method: "GET",
    }
    console.log("source", source)

    return (
      <Pdf
        source={source}
        onLoadProgress={percent => {
          console.log("percent", percent)
        }}
        style={styles.pdf}
      />
    )
 }
pwener commented 4 years ago

Same issue here.

standreinmcp commented 3 years ago

Same issue here. I observed that when you download pdf that have .pdf extension, the progres will work correctly.

The negative value is from the file's size in KB if I'm not mistaken.

The loader doesn't work because I think, it can't recognises your file as being a pdf, although it shows you the pdf correctly after it has loaded.

This is what I get but nonetheless it works in showing the pdf.

Maybe some tweaking from the api would be a possible fix ?

Screenshot 2021-10-09 at 02 47 17

For example, a random pdf from web should work: https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf Keep in mind that it has to be secure ( https, not http )