尝试使用react-pdf渲染一个pdf,我发誓我已经完成了他们的文档的所有配置,但没有任何工作。我不断地得到
ReferenceError: $RefreshReg$ is not defined
概念证明组件。是的,在这段代码中没有使用这些选项,但我尝试过使用它。我尝试将cmap直接引入到这个组件中并在那里引用它。我尝试了复制webpack插件,并完全按照文档中的建议操作。没有一样东西起作用。总是出现同样的错误。希望我错过了一些小细节。
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-empty-function */
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { Container, Paper } from '@material-ui/core';
import React, { useState } from 'react';
import { Document, Page } from 'react-pdf/dist/esm/entry.webpack';
import { pdfjs } from 'react-pdf';
import 'react-pdf/dist/esm/Page/AnnotationLayer.css';
pdfjs.GlobalWorkerOptions.workerSrc = 'pdf.worker.min.js';
const options = {
cMapUrl: `//cdn.jsdelivr.net/npm/pdfjs-dist@${pdfjs.version}/cmaps/`,
cMapPacked: false
};
export default function TVRPreview() {
const [numPages, setNumPages] = useState(null);
const [pageNumber, setPageNumber] = useState(1);
function onDocumentLoadSuccess({ numPages }: any) {
setNumPages(numPages);
}
return (
<Container>
<Paper>TVR Preview</Paper>
<Paper elevation={6}>
<Document file="./PDFTestTVR.pdf" onLoadSuccess={onDocumentLoadSuccess}>
<Page pageNumber={pageNumber}></Page>
</Document>
</Paper>
</Container>
);
}
项目详情
使用react- App -rewired创建React应用程序
"start":"react-app-rewired start",
发布于 2021-07-21 01:19:02
为了确保一切都正常工作,请执行以下步骤:
将const options
更改为:
const options = {
cMapUrl: 'cmaps/',
cMapPacked: true,
};
还有这里:
<Document file="./PDFTestTVR.pdf" onLoadSuccess={onDocumentLoadSuccess}>
将此文件引用更改为位于互联网上某个位置的任何pdf。
发布于 2021-10-19 05:30:04
这里可能有两个问题..
pdfjs.version
而不是传入pdfpdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`;
文档:react-pdf
https://stackoverflow.com/questions/67078951
复制相似问题