0

I have an async function which draws an image in my pdf:

const doc = new jsPDF();
var base = "";
async function setimage(){
   base = await loadheaderImageAsURL("/logo.png");    
   doc.setFillColor(128, 29, 5);
   doc.rect(167,43,33,10,'F');
   doc.setFillColor(4, 141, 196);
   doc.rect(167,60,33,10,'F');
   doc.addImage(base,'PNG',168,45,50,50);
}

document.getElementById('generate').addEventListener('click',async function(){

     setimage(); //doesn't work
     var base_1 = await loadheaderImageAsURL("/logo1.png");
     doc.addImage(base_1,'PNG',168,45,50,50); // this works
     doc.save("report.pdf");
})

The function isn't working. How do I fix this?

Rayon
  • 36,219
  • 4
  • 49
  • 76

1 Answers1

0

As suggested by @bill.gates, setting await setimage(); works, as the function executes only after getting a promise