问题
I'm trying to generate a pdfd file with multiples images, i can put one image in pdf document but i can't add more than one image, i think that i need do a loop but i don't know how :S, somebody can help me to structure my code and generate a pdf with multiple images?, this is my code..
function pruebaPDF(){
html2canvas($(".jspdf2"),{
onrendered: function(canvas){
var height = $(".jspdf1").height();
var data = canvas.toDataURL("image/png"),
doc = new jsPDF({
orientation:'p',
unit:'mm',
format:'letter'
});
doc.addImage(data, 'PNG', 10, 6, 185, height);
//doc.addPage();
doc.save('tqwe.pdf');
}
});
}
回答1:
You can create a new variable for your image and use the addImage() function:
var imgData = 'data:image/jpeg;base64,'+ Base64.encode('yourimage.jpeg');
doc.addImage(imgData, 'JPEG', 15, 40, 180, 160);
Hope it helps.
回答2:
The link below is a tutorial on how to make a form into a pdf. that would include all the images / text boxes css ect... this should hold all the answers you need. If you need extra help dont hesitate i can guide you further. http://www.techumber.com/2015/04/html-to-pdf-conversion-using-javascript.html
来源:https://stackoverflow.com/questions/39453922/multiples-images-in-jspdf