AddyProg
AddyProg

Reputation: 3050

Converting Canvas to Pdf using JsPDF

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');
                }
          });
       }

Upvotes: 14

Views: 42134

Answers (2)

DyC
DyC

Reputation: 1

function canvas2pdf(){ var img =canvas.toDataURL();
var pdf = new jspdf.jsPDF(); pdf.addImage(img, 'JPEG', 0, 0); pdf.save('canvas.pdf'); }

Upvotes: 0

diegocr
diegocr

Reputation: 1000

Try this instead:

var pdf = new jsPDF('p','pt','a4');

pdf.addHTML(document.body,function() {
    pdf.output('datauri');
});

See http://mrrio.github.io/jsPDF/

Upvotes: 10

Related Questions