Invalid image error using dataUrl in pdfmake
OK, I'm chalking this one up to an ID-10-T error. My line with the base64 encoded URL is working fine. I found another line farther down in my doc definition object where I wasn't referring to the image properly, and that one was throwing the error.
you can try like this. and it will work fine. Don't forget to vote up
getBase64ImageFromURL(url) { return new Promise((resolve, reject) => { var img = new Image(); img.setAttribute("crossOrigin", "anonymous"); img.onload = () => { var canvas = document.createElement("canvas"); canvas.width = img.width; canvas.height = img.height; var ctx = canvas.getContext("2d"); ctx.drawImage(img, 0, 0); var dataURL = canvas.toDataURL("image/png"); resolve(dataURL); }; img.onerror = error => { reject(error); }; img.src = url; });}
async createPdf() { var docDefinition = { content: [ { image: await this.getBase64ImageFromURL("../../assets/ribbonLogo1.png") },