Trying to figure out how to send a generated pdf from html2pdf (Javascript – Erik Koopmans) to the phpmailer via Ajax. I can save the document to the local users pc. But I need to be able to attach the generated pdf to an email using phpmailer.
Here’s the code where I’ve managed to generate the pdf document perfectly for saving to the users computer:
// Get div for pdf document
let page = document.getElementById('printPage');
// html2pdf options
var options = {
margin: [5, 0, 0, 0],
filename: 'test.pdf',
image: {
type: 'jpeg',
quality: 1
},
pagebreak: {
mode: ['legacy']
},
html2canvas: {
scale: 3
},
jsPDF: {
unit: 'mm',
format: 'a4',
orientation: 'portrait'
}
};
// SAVE DOCUMENT AS PDF
$(document).on('click', '#saveBtn', function() {
html2pdf().from(page).set(options).save();
});
This works perfectly. Now I just need to figure out how to send this same pdf to phpmailer and attach it to an email.
From what I’ve read, some people mentioned that I need to somehow use the line:
html2pdf().from(page).set(pdfOptions).toPdf().output('datauristring')
I don’t quite understand this. Am I suppose to send it as a string to php? Or is there some better way of doing it? Thanks.