Search code examples
javascriptcanvashtml2canvasjspdf

HTML2Canvas - get created canvas image URI


I had a great idea to combine html2canvas & jspdf to generate PDF-s, although generating PDF with image in jspdf requires image URI. I'm really new in that stuff so i thought that maybe it's possible to get created canvas uri aswell?

I create canvas using function:

function makeCanvas(){
var $printSection = makeImage(); //just a function to group up elements for canvas
html2canvas($printSection, {
    onrendered: function(canvas){
        console.log(canvas); //get URI???
    }
});
}

What i'd like to do now is to get the URI of created canvas. Is it even possible and if it is, then how?


Solution

  • You can use .toDataURL() to generate a data-uri:

    canvas.toDataURL()