问题
I'm trying to export an html(within a div with ID), and have managed to do so with fromHTML(), but unfortunately it doesn't read/use any css I have. This said, I tried with addHTML function, but it looks like nothing happens when I use following code:
function pdfExport(id) {
window.html2canvas = html2canvas;
var dddoc = new jsPDF('p', 'px', 'a4');
var elem_to_export = $("#cmodal-id-" + id)[0];
dddoc.addHTML(document.body, function(){
console.log('saving');
dddoc.save('test.pdf');
});
}
Also, note that I don't get anything printed into console. Not sure if it's worth anything: Before I run this function pdfExport() - (it's ran onclick) - I get one get error in js console, as said image doesn't exist. Now, when I run the function, same error appears again, just as if that image is tried to be loaded again.
回答1:
This wasn't working because I used latest versions of both html2canvas and jsPDF. When I changed those to load from:
'https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js', 'https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js'
everything was just working.
回答2:
Both fromHTML
and addHTML
are deprecated and no longer supported by the JsPDF team. If you still want to use addHTML
or fromHTML
you'll need to use jsPDF 1.4.1
. So check your jspdf version or migrate to the new jsPDF html
plugIn.. For code example, check this answer out.
来源:https://stackoverflow.com/questions/56403448/jspdf-fromhtml-vs-addhtml