【问题标题】:How to download the iframe as pdf document in react?I have tried using jspdf and kendo-react-pdf but getting blank document如何在反应中将 iframe 下载为 pdf 文档?我尝试使用 jspdf 和 kendo-react-pdf 但得到空白文档
【发布时间】: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


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-22
      • 1970-01-01
      • 1970-01-01
      • 2013-05-01
      • 2016-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多