使用 jsPDF 和 autotable 从 HTML Table 生成 PDF 时出错

Error while generating PDF out of HTML Table using jsPDF & autotable

我正在使用 jsPDF 和 autotable 从我的 DOM-Tree 中的 Table 生成 PDF。我的项目基于 Wordpress,我通过 CDN 注册并入队 () 这两个库。

但是当执行我的 pdf 生成代码(基本上是要测试的虚拟代码)时,它失败并出现以下错误:

Uncaught TypeError: t.getDocument().getFillColor is not a function
    f https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.5.23/jspdf.plugin.autotable.min.js:10
    c https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.5.23/jspdf.plugin.autotable.min.js:10
    drawTable https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.5.23/jspdf.plugin.autotable.min.js:10
    drawTable https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.5.23/jspdf.plugin.autotable.min.js:10
    autoTable https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.5.23/jspdf.plugin.autotable.min.js:10

由于找不到类似的问题并且无法自己解决,所以我想分享我的问题。

const doc = new jsPDF({
            orientation: "landscape",
            unit: "mm",
            format: [300, 260]
        });

doc.text(25, 25, "Header");
doc.addPage();

doc.autoTable({ html: '#my-table' });
doc.save(pdfName);
<table id="my-table" class="table table-bordered table-custom">
     <thead id="test-thead">
         <tr>
            <td>Col 1</td>
            <td>Col 2</td>
         </tr>
     </thead>
     <tbody id="test-tbody">
         <tr>
            <td>Test 1</td>
            <td>Test 2</td>
        </tr>
     </tbody>
</table>

我已经通过调用 autotable.js

的旧版本设法使其正常工作
    <script src="https://unpkg.com/jspdf-autotable@3.5.22/dist/jspdf.plugin.autotable.js"></script>

好像是最新的3.5.23版本,少了getFillColor的方法