I'm trying to convert the HTML content of a temporarily and locally on clients side into a real picture. I did my research canvas2base64canvas2base64html2base64, but nowhere is a real picture generated, it's always a "image" based on a base64 code.
It does what I want. It generates a picture in the quality I want it to. But the thing is, I would like to put this image into a PDF with jsPDF and when the image is a base64 code, it is not able to place it into the PDF.
I'm usig all of the following scripts: jquery.js, jspdf.js, html2canvas.js and FileSaver.js
Is there a way to temporarily generate a REAL image like a *.png or a *.jpg out of a canvas, which is not based on base64 code and is saved on the localStorage of the user? So i can reference to it and use it in my code?
The code down below should generate the image and then put the image into a PDF the size of a DIN A4.
function print() {
//const filename = 'Loveletter_.pdf';
html2canvas(document.querySelector('.finishedLetter')).then(function(canvas) {
var pdf = new jsPDF('p', 'mm', 'a4');
$("#test_me").attr("src", canvas.toDataURL("image/png", 1.0));
var ImgForPDF = document.getElementById('test_me').getAttribute('src');
pdf.addImage(ImgForPDF, 'PNG', 0, 0, 211, 298);
});
pdf.save('Loveletter_.pdf');
}