Search code examples
javascriptslickgridjspdfhtml2canvas

Jspdf to print slickgrid


I am trying to use JsPdf on a page where i utilize a slickgrid. I am using their HTML renderer which i understand is still in its early stages. Has anyone had any success with something like this or similar? Edit i have added HTML2Canvas cdn, just not sure how to implement it. here is my Fiddle

   $(document).ready(function () {
    var doc = new jsPDF();


    var specialElementHandlers = {
        '#editor': function (element, renderer) {
            return true;
        }
    };

    $('#cmd').click(function () {
        doc.fromHTML($('#entirecontent').get(0), 15, 15, {
            'width': 200,
            'elementHandlers': specialElementHandlers
        });
        doc.save('sample-file.pdf');
    });
});

Solution

  • If you can utilize html2canvas, then you can achieve it easily

    html2canvas(document.body).then(function(canvas) {
        var imgData = canvas.toDataURL("image/jpeg", 1.0);
        var pdf = new jsPDF('p', 'mm', [380, 380]);
        pdf.addImage(imgData, 'JPEG', 20, 20);
        pdf.save("screen-1.pdf");
    
    });
    

    Repo: https://github.com/niklasvh/html2canvas/