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

176
Views
Download PDF with 2 images and text on single button click using jsPDF

I am new to JavaScript and trying to add a button that exports a PDF with 2 images and some text on a on single button click.

Below is the code I currently have however, it only works when I double click the button.

How would I get this to work on a single click?

<div class="radarChartBox">
<canvas id="radarChart"></canvas>
<button id="downloadPDF" onclick="downloadPDF()">download PDF.</button>
</div>

<script>
function downloadPDF() {
const canvas = document.getElementById('radarChart');
const canvasImg = canvas.toDataURL('image/jpeg', 1.0);
const bannerImg = new Image;
bannerImg.src = "https://slipstreamgroup.com.au/wp-content/uploads/2022/03/Banner-img.jpeg";
    
let pdf = new jsPDF();
pdf.setFontSize(24);
pdf.setTextColor(255, 255, 255);
pdf.addImage(bannerImg, 'JPEG', 0, 0, 210, 55, "alias1");
pdf.text(10, 25, 'Your ' + formTitle);
pdf.addImage(canvasImg, 'JPEG', 10, 60, 190, 190, "alias2");
pdf.save(firmName + " " + formTitle + ".pdf");
}
</script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your code is not really fixable as not normal as a minimal running example of a problem since you have undefined variables and chunks of code all over the place with no <html><head><style><body> structure.

By far the simplest way is to use the demos and documentation to see the possibilities so the full working system is one zip file https://github.com/parallax/jsPDF/archive/refs/heads/master.zip, unpack and run jsPDF-master/jsPDF-master/index.html (may take a few seconds as it does a lot) to try the demo off line then trim it back to simply emulate the button as on that page. so here I changed the stock example to double the demo image and shuffle the text around. the download works in one click

enter image description here

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!