Привет, я в настоящее время застрял с отображением pdf файла. Я использую response-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";
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${
pdfjs.version
}/pdf.worker.js`;
class PDFShow extends Component {
constructor(props) {
super(props);
this.state = {
numPages: null,
pageNumber: 1
};
}
onDocumentLoadSuccess = ({ numPages }) => {
this.setState({ numPages });
};
render() {
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);