addImage Error using URL
See original GitHub issueAre you using the latest version of jsPDF? Yes, the problem occurs in 1.5.3. The same code works in 1.4.1
Have you tried using jspdf.debug.js? Yes
Steps to reproduce
var doc = new jsPDF();
doc.addImage("https://promo.bradbrownmagic.com/pdf-flyer/flyers/poster-dark-cmyk.jpg","JPEG",0,0);
doc.save();
Here’s a fiddle with the minimal example.
https://jsfiddle.net/magicalbrad/sg4ba31x/
What I saw Using 1.4.1, the code works. Using 1.5.3, addImage fails and execution stops. I get a console error:
Uncaught Error: Supplied Data is not a valid base64-String jsPDF.convertStringToImageData at Object.jsPDFAPI.convertStringToImageData (jspdf.debug.js:7627) at Object.jsPDFAPI.addImage (jspdf.debug.js:7567) at window.onload ((index):35)
What I expected I expected it to work under the new version as it did previously.
I worked around this by updating my site’s live code to pass a base64 encoded string instead of a URL, so I’m OK. But, I thought it would be worth mentioning that this functionality is broken. (Unless it is no longer supported, but it looks like it wasn’t intentionally removed.)
BTW: Thanks for all your work on this awesome project!
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:20
Top GitHub Comments
This is still an issue as although dist is on 2.1.1, the last release is 1.5.3 and the fix above wasn’t applied in that release.
To fix it, simply load your image first;
thank you @rob101 var img = new Image(); img.src = ‘https://XXX/logo.png’; doc.addImage(img, “PNG”, 345, 117, 32, 32)