[英]Error “jsPDF canvas plugin not installed” with html2pdf.js and Webpack
I'm migrating an Angular app to Webpack which uses the html2pdf.js
library. 我正在将Angular应用程序迁移到使用
html2pdf.js
库的html2pdf.js
。
After having added the package with yarn add html2pdf.js@0.9.0
and added the import 'html2pdf.js'
, when I call html2pdf(element, opt)
, it shows an alert message : 用
yarn add html2pdf.js@0.9.0
软件包后, yarn add html2pdf.js@0.9.0
并添加import 'html2pdf.js'
,当我调用html2pdf(element, opt)
,它显示一条警报消息:
jsPDF canvas plugin not installed
To me it seems like the jspdf lib is loaded, but the canvas plugin is missing or miss-loaded. 在我看来,jspdf库已加载,但是canvas插件丢失或未加载。
This seems to come from the jsPDF package where come from this alert . 这似乎来自此警报发出的jsPDF软件包。
Could anyone help me on getting this working please? 有人可以帮我解决这个问题吗?
I finally got it working by aliasing html2pdf.js as html2pdf : 我终于通过将html2pdf.js别名为html2pdf使其工作:
environment.plugins.append('Provide', new webpack.ProvidePlugin({
$: 'jquery',
html2pdf: 'html2pdf.js',
...
}));
I have also changed the way to use html2pdf
(but it didn't solved the issue when I did it). 我也改变了使用
html2pdf
的方式(但是当我这样做时并没有解决问题)。
I was using it like this : 我正在这样使用它:
var element = document.getElementById('workstations-peripherals-table')
var opt = {
filename: 'grid.pdf',
margin: 10,
jsPDF: {
format: 'a4',
orientation: 'landscape'
}
}
html2pdf(element, opt)
And now I'm using the promise way: 现在我正在使用诺言方式:
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.