Reputation: 208
Trying this code
pdfGenerate.js
generatePDF = function() {
var imgData = 'D:/work/TiffImages/png/895153.0000.png';
var doc = new jsPDF('p', 'pt', 'a4');
doc.text(20, 20, 'CTS Aarchival');
doc.addImage(imgData, 'PNG', 15, 40, 180, 180);
doc.save('CTStest.pdf'); }
Error:
Uncaught TypeError: doc.addImage is not a function
In HTML I am just calling this method onclick() And all required js files are included.
Upvotes: 2
Views: 16839
Reputation: 208
Simple solution:
Instead of using jsPDF.js library use jsPDF.debug.js , it includes all the modules which we need.
Upvotes: 5
Reputation: 1640
You can also do it in this way:
var pdf = new jsPDF();
var img = new Image;
img.onload = function() {
pdf.addImage(this, 10, 10);
pdf.save("CTStest.pdf");
};
img.crossOrigin = "";
img.src = 'D:/work/TiffImages/png/895153.0000.png';
Upvotes: 3
Reputation: 12552
addImage
function is in another module called *drumroll please* addImage
. So if you're importing the jsPdf.js
it doens't contain that module.
Here is the doc link. Also check out these github issues here and here
Upvotes: 4