Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

What must I do if html2canvas is not defined?

Asked by Bruce Benedict Feb 28, 2023 3.4K views 2 answers
Share

About this question

 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>

Your answer

2 Answers

Ranjana Admin JanBask Expert Latest answer

Answered on Jun 4, 2024

If html2canvas is not defined, follow these steps:


Include the Script: Ensure you have included the html2canvas library in your HTML file:

[removed][removed]

Install via npm: If using npm, install the library and import it:

npm install html2canvas

import html2canvas from 'html2canvas';

Check for Typos: Verify there are no typos in the script tag or import statement.

Network Issues: Make sure there are no network issues blocking the script from loading.

By following these steps, you can resolve the issue of html2canvas not being defined.


Was this helpful?

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.