How can I generate an image of my site using jspdf and html2canvas?

0

I tried to do it using this code but it does not work for me

    function genPDF() {

        html2canvas(document.body, {
            onrendered: function(canvas) {

                var img = canvas.toDataURL("image/png");
                var doc = new jsPDF();

                doc.save('document.pdf');

            }
        });

    }
    
asked by Jos torres 10.11.2017 в 04:00
source

1 answer

0

Simple you only need to add the image to the document:

function genPDF() {
    html2canvas(document.body, {
        onrendered: function(canvas) {
            var img = canvas.toDataURL("image/jpeg");
            var doc = new jsPDF();
            doc.addImage(img, 'JPEG', 0, 0); //agregar la imagen al documento
            doc.save('document.pdf');
        }
    });
}
    
answered by 10.11.2017 в 05:29