diegomura / react-pdf

📄 Create PDF files using React
https://react-pdf.org
MIT License
14.72k stars 1.17k forks source link

Error Displaying PDF #624

Closed MahdiHadrich closed 3 years ago

MahdiHadrich commented 5 years ago

Hello , We are currently working on a react web application and we want to display a pdf from a remote server on our web page using React-PDF but it didn't work, it always downloads the file rather than displaying it ..and it shows the folloing error: Unexpected server response (204) while retrieving PDF .. Can you please help us out?

EDIT: IDM was the problem preventing the pdf from displaying. I succeeded to display the pdf by disabing the IDM.

We’ve found the following line in google inspect element tool: 204 Intercepted by the IDM Advanced Integration

Is there any way to ignore/disable IDM when running the React app ?

Here is our implementation of React-PDF:

import React, { Component } from "react"; //import { Document, Page } from "react-pdf"; import { Document, Page, pdfjs } from "react-pdf"; import PropTypes from "prop-types"; import { connect } from "react-redux"; class PDFShow extends Component { constructor(props) { super(props); this.state = { numPages: null, pageNumber: 1 }; } onDocumentLoadSuccess = ({ numPages }) => { this.setState({ numPages }); }; render() { pdfjs.GlobalWorkerOptions.workerSrc = //cdnjs.cloudflare.com/ajax/libs/pdf.js/${ pdfjs.version }/pdf.worker.js;

const { current } = this.props.currentResource;
const file = "/api/documents/" + current.name;
return (
  <div>
    <Document file={file} onLoadSuccess={this.onDocumentLoadSuccess}>
      <Page pageNumber={this.state.pageNumber} />
    </Document>
    <p>
      Page {this.state.pageNumber} of {this.state.numPages}
    </p>
  </div>
);

} } PDFShow.propTypes = { currentResource: PropTypes.object.isRequired };

const mapStateToProps = state => ({ currentResource: state.currentResource }); export default connect( mapStateToProps, {} )(PDFShow);

ellej16 commented 5 years ago

Hello @H-Mah-D ! This might be the library you should post the issue on, since it uses pdfjs: https://github.com/wojtekmaj/react-pdf