I'm migrating an Angular app to Webpack which uses the html2pdf.js
library.
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 :
jsPDF canvas plugin not installed
To me it seems like the jspdf lib is loaded, but the canvas plugin is missing or miss-loaded.
This seems to come from the jsPDF package where come from this alert .
Could anyone help me on getting this working please?
I finally got it working by aliasing html2pdf.js as 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).
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.