Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, Recently I had been asked by a client that they require to download all CRM Forms as PDF.
I tried with html2canvas and jspdf libraries , but i was not able to download the form completely.
Please guide me if i am doing something wrong in the below code or there is any other way to do so.

What I have tried:

JavaScript
function createPDF() {
        var a4 = [595.28, 841.89];
            
            var div = $('#HeaderTilesWrapperLayoutElement', window.parent.document);

            var xxxx = $($(div.context).find('iframe')[0]).contents().find("body");

            var xxx = xxxx.find("#tdAreas");
            var cache_width = xxx.width();
           
            $('body').scrollTop(0);
            getCanvas().then(function (canvas) {
                var
                 img = canvas.toDataURL("image/png"),
                 doc = new jsPDF({
                     unit: 'px',
                     format: 'a4'
                 });
                doc.addImage(img, 'JPEG', 20, 20);
                doc.save('techumber-html-to-pdf.pdf');
                 xxx.width((a4[0] * 1.33333) - 80).css('max-width', 'none');
            });
        }

        // create canvas object
        function getCanvas() {
            xxx.width((a4[0] * 1.33333) - 80).css('max-width', 'none');
            return html2canvas(xxx, {
                imageTimeout: 2000,
                removeContainer: true
            });
        }
Posted
Updated 13-Dec-16 4:03am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900