I am using jsPDF to save the output of a div on my page to PDF
My Code so far is:
function makepdf() {
var doc = new jsPDF();
var html=jQuery('.js-requester-info').html();
alert (html);
doc.fromHTML(html , 15, 15, {
'width': 800
});
doc.save('test');
}
The code works, but the generated PDF file is always blank. I have added a "debug" line and
alert (html);
outputs some html code from the div, but how come the PDF is always empty?
UPDATE: I added some delay ( I found someone talnkig about delay in rendering) and now it's working:
setTimeout(function(){
doc.save('test');
},2000);
You can add a callback option
let doc = new JsPDF({ orientation: 'p', format: 'a4' })
console.log(document.getElementById('offer').innerHTML)
doc.fromHTML(document.getElementById('offer').innerHTML, 1, 1, {
elementHandlers: function() {
return true
}
}, function() {
doc.save('test')
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With