question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

addImage Error using URL

See original GitHub issue

Are 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:20

github_iconTop GitHub Comments

8reactions
rob101commented, Apr 27, 2020

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;

    var img = new Image();
    img.src = '/path/to/image.png';
    doc.addImage(img, "PNG", 1, 1);
4reactions
wpplumbercommented, Jun 2, 2020

thank you @rob101 var img = new Image(); img.src = ‘https://XXX/logo.png’; doc.addImage(img, “PNG”, 345, 117, 32, 32)

Read more comments on GitHub >

github_iconTop Results From Across the Web

addImage Error using URL #2201 - parallax/jsPDF - GitHub
Yes, the problem occurs in 1.5.3. The same code works in 1.4.1 Have you tried using jspdf.debug.js? ... addImage Error using URL #2201....
Read more >
addImage error (Cannot read property ... - Stack Overflow
I am developing an elearning course with the possibility of downloading certificate after successful completion of the course.
Read more >
ImgBB — Upload Image — Free Image Hosting
Free image hosting and sharing service, upload pictures, photo host. Offers integration solutions for uploading images to forums.
Read more >
Display images and documents - AppSheet Help
This article explains how to construct a link to a Dropbox image. Local Computer: An image URL from your local computer of the...
Read more >
Add images to a slide - Google Developers
When adding an image, you provide the Google Slides API with a publicly accessible URL to the image. About images. Images in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found