What must I do if html2canvas is not defined?

1.1K    Asked by bruce_8968 in Salesforce , Asked on Feb 28, 2023

 I need to call the jsPdf function, however in the console I am getting genPdf is not defined.

Here is my code--


  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />


    <title>Universal Health Fellowship</title>
       <!-- [removed][removed]
        [removed][removed]
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
        [removed][removed]     
        [removed][removed] -->
        [removed][removed]
        [removed][removed]     
        [removed]


        
        
        
           <style>
               @media print {
                  #printPageButton {
                    display: none;
                  }
                }
            </style>
            [removed]
                function genPdf(){
                    html2canvas(document.body,{
                        onrendered: function(canvas){
                            var imgData = canvas.toDataURL('image/png');
                            console.log('Report Image URL: '+imgData);
                            var doc = new jsPDF('p', 'mm', [297, 210]); //210mm wide and 297mm high
                            doc.addImage(imgData, 'PNG', 10, 10);
                            doc.save('sample.pdf');
                        }
                    });
                }
            [removed]
  </head>
  <body style="padding:20px;">
  <button type="button" id="printPageButton" class="btn btn-primary" onclick="genPdf();">Print</button>

If html2canvas is not defined - Removing html2Canvas library and changing code like below will resolve your issue.



   
   
   
    Universal Health Fellowship
   
   
   
   
   
        function genPdf(){
        html2canvas(document.body,{
            onrendered: function(canvas){
                var imgData = canvas.toDataURL('image/png');
                console.log('Report Image URL: '+imgData);
                var doc = new jsPDF('p', 'mm', [297, 210]); //210mm wide and 297mm high
                doc.addImage(imgData, 'PNG', 10, 10);
                doc.save('sample.pdf');
            }
        });
    }
   

Your Answer

Interviews

Parent Categories