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.
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.
Share Improve this question asked Nov 29, 2018 at 14:08 Adarsh SinghAdarsh Singh 2081 gold badge3 silver badges17 bronze badges 1- Problems with addImage. Which file are you importing? – reisdev Commented Nov 29, 2018 at 14:17
3 Answers
Reset to default 5Simple solution:
Instead of using jsPDF.js library use jsPDF.debug.js , it includes all the modules which we need.
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
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';