【发布时间】:2022-12-05 09:52:21
【问题描述】:
import { PDFExport, savePDF } from '@progress/kendo-react-pdf';
const [contentRef, setContentRef] = useState('');
const downloadCertificate = () => {
const element: any =
document.querySelector('#certificate') || document.body;
savePDF(element, { paperSize: 'A4' });
};
const onClickDownload = () => {
downloadCertificate();
};
return (
<div>
<PDFExport ref={pdfExportComponent} paperSize="A4">
<iframe
id="certificate"
title="View your certificate"
className="u-els-margin-left-3x u-els-margin-right-3x"
width="776px"
height="600px"
srcDoc={contentRef}
/>
</PDFExport>
</div>
);
使用上面的代码集生成 pdf,我正在导入 PDF 导出并将其包装在我想导出为 pdf 的代码块周围。在这里,iframe 的
srcDoc正是我想要导出的,它分配给了useState。因此,在页面呈现后,信息存储在srcDoc中,我想在单击作为返回一部分的按钮时将其导出为 pdf。
【问题讨论】:
标签: reactjs kendo-ui pdf-generation jspdf