React-pdf: Can't load pdf using URL/Data parameter

Created on 10 Dec 2018  路  5Comments  路  Source: wojtekmaj/react-pdf

I'm trying to load a PDF file using data object or URL but react-pdf only output "Loading PDF".
I'm listening for events onLoadSuccess, onLoadError, onRenderSuccess, onRenderError but only onLoadSuccess has being fired.

image

I'm also trying to load using data parameter {data: UIntArray} loaded with a fetch request (cors checked)

image

This is the object passed as parameter

*
image
*

The url used in this example is public

React-PDF Document renders "Loading PDF ..."

Can someone help?

Most helpful comment

I would add that you should store the Uint8Array file in the format { data: file } directly in the props otherwise you could face an issue where the page keeps rendering (see issue #308 for more information on this topic).

All 5 comments

I have the same issue. I provide a Uint8Array to the file props of the Document component like this

<Document
    file={{ data: file }}
 >

where file is a Uint8Array.
I try to log each method : onLoadSuccess, onLoadError, onSourceError, onSourceSuccess.
Only onSourceSuccess is fired.

EDIT

I had the issue with worker so I've added these lines :

import { Document } from 'react-pdf/dist/entry.webpack';
import { pdfjs } from 'react-pdf';
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`;

But I think there is an error with webpack because in my browser console I can see :

Uncaught ReferenceError: window is not defined

Do you have an idea about this issue ?

@AntoninMarchardDev See the bottom of #190

I would add that you should store the Uint8Array file in the format { data: file } directly in the props otherwise you could face an issue where the page keeps rendering (see issue #308 for more information on this topic).

I would add that you should store the Uint8Array file in the format { data: file } directly in the props otherwise you could face an issue where the page keeps rendering (see issue #308 for more information on this topic).

OMG, you're a life savior!
I had the exact same issue, and I was this close to giving up and starting to implement the whole thing from the ground up with pdf.js =))
Thanks a million

I would add that you should store the Uint8Array file in the format { data: file } directly in the props otherwise you could face an issue where the page keeps rendering (see issue #308 for more information on this topic).

YES! I also had this issue. This fixed the continuous rerendering problem.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shivekkhurana picture shivekkhurana  路  4Comments

Solitaryo picture Solitaryo  路  5Comments

varand-pez picture varand-pez  路  3Comments

Crackiii picture Crackiii  路  3Comments

herneli picture herneli  路  3Comments