Skip to content
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

Works locally, but on server preview shows loading ... and doesnt change. #371

Closed
sesanka opened this issue Mar 7, 2019 · 10 comments
Closed

Comments

@sesanka
Copy link

sesanka commented Mar 7, 2019

It works as expected when i run locally. But on my server it keeps saying loading PDF ...
Also locally i see there is a get request to the url to get the pdf file, but on the server there is no request to get the pdf from url.

Code:

this.state = {
      numPages: null,
      pageNumber: 1,
}

onDocumentLoadSuccess = ({numPages}) => {
    console.log(numPages);
    this.setState({numPages});
}

render() {
    return (
...
<Row>
          <Col xs={12}>
            Test Preview pdf.
          </Col>
          <Document
            file={"https://gsi.berkeley.edu/media/sample-recommendation-letter.pdf"}
            onLoadSuccess={this.onDocumentLoadSuccess}>
            <Page height={150} scale={1} pageNumber={1}
                  onLoadProgress={this.onLoadProgress}/>
          </Document>
</Row>
)
}

Local device:
image

image

Server:
image

and no requests to fetch pdf.

@sesanka sesanka changed the title Works locally, preview shows loading ... and doesnt change on server. Works locally, but on server preview shows loading ... and doesnt change. Mar 7, 2019
@wojtekmaj
Copy link
Owner

No requests at all? Hmmm, did pdf.worker.js got loaded correctly on the server?

@sesanka
Copy link
Author

sesanka commented Mar 14, 2019

image

Yes I think so.

@wojtekmaj
Copy link
Owner

Any errors in the console? Any network errors? Try and hook to onLoadError prop to see if React-PDF is not crashing, perhaps?

@cbaron
Copy link

cbaron commented Apr 3, 2019

A similar thing is happening to me.

import { Page, Document } from 'react-pdf/dist/entry.webpack';

No request is being made to get the worker.

@alex-shamshurin
Copy link

alex-shamshurin commented Apr 9, 2019

Worker has been built built separately, outside of main entry and not included or referenced from main.js and not linked from react-pdf.

@NikkiTheBugSlayer
Copy link

Did anyone figure out how to fix this?

@cbaron
Copy link

cbaron commented Apr 29, 2019

The following worked for me in webpack v4 production build:

import { Page, Document } from 'react-pdf/dist/entry.webpack';

For the webpack-dev-server we went with:

import { Page, Document } from 'react-pdf';

@NikkiTheBugSlayer
Copy link

@cbaron That worked thanks

@leonardo2204
Copy link

@cbaron How did you do that? Where can I put these different imports?
Thanks!

@sesanka
Copy link
Author

sesanka commented Oct 10, 2019

In package.json adding "react-pdf" to "dependencies" instead of "devDependencies" solved the issue and then using it as follows solved my issue:

import { Page, Document } from 'react-pdf'; 

@sesanka sesanka closed this as completed Oct 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants