html - 使用 React-pdf,按照说明进行操作,但仍然无法加载。如何修复此错误?
问题描述
我一直在关注这个在我的网站上查看我的 pdf,由于某种原因它不会加载,我不确定我做错了什么。
这是我的代码,
import React, { Component } from 'react';
import {Document, Page} from 'react-pdf';
class Resume extends Component {
constructor(props){
super(props);
this.state = {
numPages: null,
pageNumber: 1
}
}
onDocumentLoad = ( {numPages}) => {
this.setState({numPages});
}
render() {
const {pageNumber, numPages} = this.state;
return (
<div>
<Document
file = '../files/resume.pdf'
onLoadSuccess = {this.onDocumentLoad}
>
<Page pageNumber = {pageNumber} />
</Document>
<p> Page {pageNumber} of {numPages}</p>
</div>
);
}
}
export default Resume;
这是我的目录和文件!
解决方案
您是否在 webpack 配置中配置了文件加载器?
{
test: /\.pdf$/,
use: 'file-loader?name=[path][name].[ext]',
},
我正在使用文件加载器 3.0.1,我可以很好地从我的文件系统加载 PDF。
您当然还需要像这样在顶部导入它:
import resume from '../files/resume.pdf';
推荐阅读
- linux - 运行 openvas-setup
- r - 如何从现有的按天和个人分组并计算比例的数据框创建新的数据框?
- php - 获取字符串中每个字符的字符类型
- ruby-on-rails - 重定向后会话为空
- python-3.x - 可以连接到本地主机但不能远程,pyspark
- linux - 通过环境变量限制 TensorFlow GPU 内存使用
- c++ - 为什么我的 void 函数没有返回正确的值?(C++ 的新手)
- http - 为什么同源策略不阻止 POST 请求?
- jquery - 如何删除全日历 ASP.NET Core MVC 中的事件?
- tensorflow - AttributeError:模块“keras_preprocessing.image”没有属性“DataFrameIterator”