如何在React中下载iFrame作为PDF文档?我尝试使用JSPDF和Kendo-ReAct-PDF,但获取空白文档
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,单击“返回”的按钮。
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>
);
Using the above set of code to generate the pdf, I am importing the PDF Export and wrapping it around the block of code i want to export as pdf. Here the
srcDoc
of iframe is what I exactly want to export which assigned to auseState
. So after the page renders the info is stored insrcDoc
and I want to export this as pdf on click of the button which is part of the return.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当前
iframe
s不受PDF导出的一部分支持: https://www.telerik.com/kendo-react-ui/components/components/drawing/limitations-limitations-limitations-browser-support/#toc-epport/#toc-elements-and-elements-and-elements-and-eng--------------样式currently
iframe
s are not supported as part of the PDF export: https://www.telerik.com/kendo-react-ui/components/drawing/limitations-browser-support/#toc-elements-and-styles