React-pdf: PDF.js getDocument promise does not come back

Created on 2 Apr 2019  ·  4Comments  ·  Source: wojtekmaj/react-pdf

Before you start - checklist

  • [/] I have read documentation in README
  • [/] I have checked sample and test suites to see real life basic implementation
  • [/] I have checked if this question is not already asked

What are you trying to achieve? Please describe.

I've upgraded from Version 3.0.5 to 4.0.5. After the update my PDF-Files will not be displayed anymore and it keeps "loading".

Describe solutions you've tried

I display my PDF-File as base64-data but tried plain bytes too. Using the provided notification hooks gives me the feedback, that sourcedata is loaded correctly.
Debugging into your code leads me to Document.js and this code:

  cancellable = (0, _utils.makeCancellable)(loadingTask.promise);
  _this.runningTask = cancellable;
  _context.next = 23; // until here is everything fine
  return cancellable.promise; // this promise is never resolved 

Additional information

I use your lib straight forward:

import { Document, Page } from "react-pdf/dist/entry.webpack";
 <Document
          file={ isDataBase64 ? `data:application/pdf;base64,${file}` : file }
          loading="Das PDF wird geladen..."
          onLoadSuccess={ ::this.onDocumentLoadSuccess } // show additional buttons for zoom
          className="pdfDocument"
          renderMode="svg"
        >
            <Page
              key={ `page_${1}` }
              pageNumber={ 1 }
              className="pdfPage"
              renderMode="svg"
              scale={ pageScale } />
        </Document>

I've attached a sample PDF for you. Copy+paste it into your browser will work. Using it at the parameter for <Document file={<pdfdata here>}> does not work.
samplePDF_base64.txt

Environment

  • Browser (if applicable) [e.g. Chrome 57, Firefox 59]: Chrome and FF latest
  • React-PDF version [e.g. 3.0.4]: 4.0.5
  • React version [e.g. 16.3.0]: 16.3.2
  • Webpack version (if applicable) [e.g. 4.16.2]: 3.8.1
question

Most helpful comment

In case it's helpful to anyone else, I also experienced the same never-resolving promise behaviour when I'd accidentally set the url for the worker (pdfjsLib.GlobalWorkerOptions.workerSrc = "....") to point to the main pdf.js file instead of the pdf.worker.js file by mistake.

All 4 comments

It definitely worked for me both pasting it in browser's address field and passing as an URL to file prop in React-PDF! Maybe you're "base64-ing" it twice?

obraz

No, this pdf-data is equal to the string, I pass into Document.
Is there any way to find out what PDFjs is doing?

Damn, this caching.

Deleting all the site caches in Chrome made it work.

Thanks for your fast answer!

In case it's helpful to anyone else, I also experienced the same never-resolving promise behaviour when I'd accidentally set the url for the worker (pdfjsLib.GlobalWorkerOptions.workerSrc = "....") to point to the main pdf.js file instead of the pdf.worker.js file by mistake.

Was this page helpful?
0 / 5 - 0 ratings