Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

264
Views
jspdf doesn't work when loaded from a CDN

I am going to use package(jspdf) loaded from **CDN **

this is CDN

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>

and I have loaded it like this in a page :

mounted() {
  if (document.getElementById('myScript')) { return }
  let src = 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js'
  let script = document.createElement('script')
  script.setAttribute('src', src)
  script.setAttribute('type', 'text/javascript')
  script.setAttribute('id', 'myScript')
  document.head.appendChild(script)
}

and I have a button that when you click on it a below method will called and some pdf will be generated.

generateReport() {
  var doc = new jsPDF('l', 'mm', [62, 32])
  const margins = {
    top: 0,
    bottom: 60,
    left: 0,
    width: 122
  }

  doc.fromHTML(this.$refs.print, margins.left, margins.top, {
    width: margins.width
  })

  doc.save('test.pdf')
}

BUT I get an error

enter image description here

So, how can I fix this error?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use const { jsPDF } = window.jspdf; as shown in the official documentation if you want to use the CDN.

Even tho, I still do recommend the NPM package way (so does the package itself).

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!