Converting Canvas to Pdf using JsPDF

38,171

Try this instead:

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

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

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

Share:
38,171
Addy
Author by

Addy

Android App Developer by choice and Web Developer by force, love PC games, love football and cricket.

Updated on July 17, 2022

Comments

  • Addy
    Addy almost 2 years

    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');
                    }
              });
           }
    
  • Addy
    Addy almost 10 years
    it says ..pdf.addHTML(document.body,function()
  • Addy
    Addy almost 10 years
    sorry, means debugger is not recognizing this addHTML function
  • diegocr
    diegocr almost 10 years
    addHTML is a new jsPDF plugin, pick the latest version from github.com/MrRio/jsPDF/tree/master/dist
  • Mohammad Faizan khan
    Mohammad Faizan khan about 9 years
    blurry image found using this sadly