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

Flo*_*ode 1 javascript jspdf jspdf-autotable

我正在使用 jsPDF 和 autotable 从 DOM 树中的表生成 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
Run Code Online (Sandbox Code Playgroud)

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

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);
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)

Com*_*nd0 5

我设法通过调用旧版本的 autotable.js 让它工作

    <script src="https://unpkg.com/jspdf-autotable@3.5.22/dist/jspdf.plugin.autotable.js"></script>
Run Code Online (Sandbox Code Playgroud)

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