html2pdf.js 和 Webpack 的错误 "jsPDF canvas plugin not installed"

Error "jsPDF canvas plugin not installed" with html2pdf.js and Webpack

我正在将 Angular 应用程序迁移到使用 html2pdf.js 库的 Webpack。

在使用 yarn add html2pdf.js@0.9.0 添加包并添加 import 'html2pdf.js' 之后,当我调用 html2pdf(element, opt) 时,它显示一条警告消息:

jsPDF canvas plugin not installed

对我来说,jspdf 库似乎已加载,但 canvas 插件丢失或未加载。

这似乎来自 jsPDF package where come from this alert

谁能帮我解决这个问题?

我终于通过将 html2pdf.js 别名为 html2pdf 使其工作:

environment.plugins.append('Provide', new webpack.ProvidePlugin({
  $: 'jquery',
  html2pdf: 'html2pdf.js',
  ...
}));

我也改了使用方法html2pdf(但是我用的时候并没有解决问题)

我是这样使用它的:

    var element = document.getElementById('workstations-peripherals-table')
    var opt = {
      filename: 'grid.pdf',
      margin:   10,
      jsPDF:    {
        format: 'a4',
        orientation: 'landscape'
      }
    }
    html2pdf(element, opt)

现在我正在使用 promise 方式:

    var element = document.getElementById('workstations-peripherals-table')
    var opt = {
      filename: 'grid.pdf',
      margin:   10,
      jsPDF:    {
        format: 'a4',
        orientation: 'landscape'
      }
    }
    html2pdf().set(opt).from(element).save()