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 e 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);
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 e 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);
Share
Improve this question
edited Apr 22, 2016 at 11:49
Antonio
asked Apr 22, 2016 at 10:53
AntonioAntonio
53510 silver badges27 bronze badges
3
- Looks like adding some timeout make it work.... – Antonio Commented Apr 22, 2016 at 11:45
- 1 interesting, this post solved my problem. Any idea why adding timeout was necessary? and why it was not including in doc? – Shadab Faiz Commented May 7, 2018 at 11:24
- tried adding timeOut as well, but works on the last page only. the previous pages shows blank :( – mars-o Commented Feb 1, 2019 at 15:54
1 Answer
Reset to default 1You 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')
})