问题描述
我正在使用 React-pdf/renderer 来呈现发票 PDF,根据用户想要查看的发票而有所不同。在第一个 pdf 视图中它可以工作,但是在关闭对话窗口并尝试查看相同的 PDF 或其他 PDF 后,它会显示我的整个应用程序。
这是我的发票组件中包含的对话框组件:
<Dialog aria-label="pdf-modal" className={classes.modalContent} fullScreen open={viewPDF} onClose={handlePDFClose} TransitionComponent={Transition}>
<AppBar className={classes.appBar}>
<Toolbar>
<IconButton edge="start" color="inherit" onClick={handlePDFClose} aria-label="close">
<CloseIcon />
</IconButton>
<Typography variant="h6" className={classes.title}>
Invoice PDF
</Typography>
</Toolbar>
</AppBar>
<PDFViewer className={classes.pdfViewer}>
<InvoicePDF
invoice={modalContent}
items={state.inventory}
account={state.accounts?.filter(x => x.accountID === modalContent.accountID)[0]}
taxRate={taxRate}
credits={invoiceCredits}
/>
</PDFViewer>
</Dialog>
这是我的 InvoicePDF 组件,它使用其他子组件进行渲染:
const InvoicePDF = (props: {
invoice: InvoiceModel,items: Itemmodel[],taxRate: number,account: AccountModel,credits: number
}) => {
const { invoice,items,taxRate,account,credits} = props;
return (
<React.Fragment>
<Document aria-label="pdf-document">
<Page size="A4" style={styles.page}>
<InvoiceTitle title='Invoice'/>
<InvoiceNo invoice={invoice}/>
<BillTo account={account}/>
<InvoiceItemsTable
invoice={invoice}
items={items}
taxRate={taxRate}
credits={credits}
/>
</Page>
</Document>
</React.Fragment>
);
}
我也在控制台中收到这些消息:
asm.js 类型错误:禁用,因为没有合适的 wasm 编译器可用 2.9353cd33.chunk.js
警告:无效的绝对 docBaseUrl:“blob:http://localhost:5000/9b5ed5ee-c427-4464-ab7b-abdefb835d35”。 pdf.worker.js:1076:13
PDF f4cdab794e2e1f6ec4f52956dab2fcf1 [1.3 react-pdf / react-pdf] (PDF.js: 2.9.273)
这是我第一次使用 PDF,所以这个问题真的让我很困惑,不明白在重新加载/未加载正确的 PDF 后对话框如何显示完整的应用程序。任何帮助都会很棒,如果我需要提供更多信息,请告诉我。谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)