How to add an image when generating a pdf-file with javascript. When adding the imageLoadFromURL no pdf is generated
- by Angu Handschuh
I've got a problem with adding an image when generating a pdf-file with javascript. Here is my code:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="base64.js"></script>
<script type="text/javascript" src="sprintf.js"></script>
<script type="text/javascript" src="jspdf.js"></script>
<script>
function demo1() {
var name = prompt('Name: ');
var nachname=prompt('Nachname: ');
var doc = new jsPDF();
doc.setFontSize(22);
doc.text(20, 20, 'Der eingegebene Text');
doc.setFontSize(16);
doc.imageLoadFromUrl('image.jpg');
doc.imagePlace(20, 40);
doc.text(20, 30, 'Name: ' + name);
doc.text(20,40,'Nachname:'+nachname);
// Output as Data URI
doc.output('datauri');
}
</script>
</head>
<body>
<h2> Ein Document </h2>
<a href="javascript:demo1()"> PDF erstellen </a>
</body>
</html>
Before adding
doc.imageLoadFromUrl('image.jpg');
doc.imagePlace(20, 40);
the code runs without picture. It starts with a demand note for the name and the second name, after this it generates a pdf-file. But when adding the imageLoad-Method there is no pdf-file generated. Does anyone konws how to solve this problem?