javascript - doc.fromHTML 不是函数
问题描述
我正在尝试将 jspdf 与我的 react 应用程序一起使用,在我的文档和 jspdf 的类型中,我可以看到有一个名为 fromHTML 的函数。但是当我尝试调用函数时,出现以下错误:
doc.fromHTML is not a function
有人可以帮帮我吗?
import { jsPDF } from 'jspdf'
const Prints = () => (
<div>
<h3>Time & Materials Statement of Work (SOW)</h3>
<h4>General Information</h4>
<table id='tab_customers' class='table table-striped'>
<colgroup>
<col span='1' />
<col span='1'/>
</colgroup>
<thead>
<tr class='warning'>
<th>SOW Creation Date</th>
<th>SOW Start Date</th>
<th>Project</th>
<th>Last Updated</th>
<th>SOW End Date</th>
</tr>
</thead>
<tbody>
<tr>
<td>Dec 13, 2017</td>
<td>Jan 1, 2018</td>
<td>NM Connect - NMETNMCM</td>
<td>Dec 13, 2017</td>
<td>Dec 31, 2018</td>
</tr>
</tbody>
</table>
<p>
This is a Time and Materials Statement of Work between Northwestern Mutual
Life Insurance Company and Infosys with all general terms and conditions
as described in the current Master Agreement and its related documents
</p>
</div>
)
function generatePdf() {
const doc = new jsPDF( 'p', 'mm', 'a4' )
let index = 0
const htmlToConvert= renderToString(<Prints />)
doc.fromHTML(htmlToConvert)
doc.save('myPdf')
}
单击按钮时调用 generatePdf 函数
解决方案
尝试将 doc.fromHTML 更改为 doc.html,如下所示:
function generatePdf() {
const doc = new jsPDF( 'p', 'mm', 'a4' )
let index = 0
const htmlToConvert= renderToString(<Prints />)
doc.html(htmlToConvert, {
callback: function (doc) {
doc.save();
}
});
}
这对你有帮助吗?
推荐阅读
- visual-studio-code - 在 Visual Studio Code (VSCode) 中,如何快速折叠光标同一级别的所有块?
- django - Django中的递归关系:从每条记录中获取所有相互关联的记录
- angular - 减少角度生产构建
- python - 如何通过使用 for 循环创建数组来提高时间效率?
- javascript - 类型 'unknown' 不能分配给类型 'any[] | 可迭代
| (可迭代 & 任何[]) - curl - 网页抓取问题(尝试过 curl、wget、headless chrome、phantomjs 但仍然有问题......)
- vb.net - 为什么我的 Visual Basic 程序会退出?它在启动后一分钟内停止执行
- html - 使用跨越几张卡片的图表作为背景
- azure-devops - 无法在 Azure Pipelines 中有条件地下载安全文件
- php - 在特定 WooCommerce 电子邮件模板上将动态值插入文本字符串