• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

148
Views
jsPDF jQuery.Deferred exception: r[o] is undefined

I am trying to use jsPDF to download a PDF version of my website. I am getting this error jQuery.Deferred exception: r[o] is undefined. I think it has to do with "var source = $("#content")[0]" in the body somehow being undefined, but I'm not sure if this is the only problem.

Necessary Imports (in head):

    <!-- jQuery library -->
  <script src="static/js/jquery.min.js"></script>

  <!-- jsPDF library -->
  <script src="static/js/jsPDF-1.3.2/dist/jspdf.min.js"></script>

/* Bootstrap at end of body */
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-U1DAWAznBHeqEIlVSCgzq+c9gqGAJn5c/t99JyeKa9xxaYpSvHU5awsuZVVFIhvj" crossorigin="anonymous"></script>

HTML

<div class="container-fluid" id="content">
    <div class="row">
        <h1>UH ENERGY</h1>
    </div>
    <div class="row">
        <a href="#" id="downloadPDF" >Download PDF</a>
    </div>
    <!--CHART 1-->
    <div class="row">
        <div class="col-md-6 col-sm-12 col-xs-12">
            <canvas id="myChart" class="bar-chart"></canvas>
    <!-- Continued -->

function in main.py

$( document ).ready(function() {
    var doc = new jsPDF(); 
    var specialElementHandlers = {
        "#bypassme": function (element, renderer) {
            return true
        }
    }; 
    var margins = {
        top: 80,
        bottom: 60,
        left: 40,
        width: 522
    }; 
    var source = $("#content")[0];
    doc.fromHTML(
        source.innerHTML,
        margins.left, 
        margins.top, 
        {
            "width": margins.width,
            "elementHandlers": specialElementHandlers
        }, 
        function (dispose) { 
            doc.save("ICEV-EV.pdf"); 
        }, 
        margins
    ); 
    });
about 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error