I am trying to convert canvas into pdf but i get clean white pdf in result Here is the code, I am not being able to figure out what i am missing..
function HtmlToImage(){
html2canvas(document.body, {
onrendered: function(canvas) {
var img =canvas.toDataURL("image/jpeg,1.0");
var pdf = new jsPDF();
pdf.addImage(img, 'JPEG', 0, 0);
pdf.output('datauri');
}
});
}
Step 1) Include jsPDF and html2canvas liberary URl in head section of your HTML. In this code block we have used html2canvas function which will give canvas of HTML section we specified, then after getting canvas object we will add PDF page using a jsPDF method and add break-up of canvas s image(JPG) in PDF page.
jsPDF is an open-source library for generating PDF documents using JavaScript. It provides multiple options to generate PDF files, with custom properties. It has numerous plugins to support various ways of PDF generation.
Try this instead:
var pdf = new jsPDF('p','pt','a4');
pdf.addHTML(document.body,function() {
pdf.output('datauri');
});
See http://mrrio.github.io/jsPDF/
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