JsPDF addimage is not a function

By On

I am using JsPDF and I want to add an image to a pdf document. I have followed the examples from the code and it seems fairly simple to make it work. For some reason I am getting a console error when I try to perform this. The error reads

"addImage is not a function". I have pulled the latest version of the code from github so I don't think this is a problem with some outdated code. Here is the code that I am using for this.

var img = new Image();
img.onload = function() {
pdfdoc.addImage(this, 10, 10);
pdfdoc.save("test.pdf");
};

1 Answer

- Advertisment -
SEMrush
Answered By Aaron Garnes On

There appears to be a bug with the older version of this framework for some people. If you have downloaded the latest version of the code it may not be the case. To test this out first, try to use the library from the CDN rather than downloading the raw code from the Github repo.

Here is the public hosting of the library. https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.2.61/jspdf.debug.js . I have used this exact url for work that I have written and it is working fine for me.