I have created already some jQuery code to make it work and it does but not exactly how it supposed to? Exactly I’m generating an invoice with HTML template that replace content and saving it as new html file. Then with jQuery on button click it should convert that generated invoice to PDF as A4 format. It does convert and downloading but when I previewing it has not properly size (does not fit content from HTML invoice).
This is code I have currently:
$('#convertToPdf').click(function(){
var invoiceUrl = $('#invoiceLink').attr('href');
$.ajax({
url: invoiceUrl,
type: 'GET',
dataType: 'html',
success: function(htmlContent) {
var doc = new jsPDF({});
doc.html(htmlContent, {
callback: function (doc) {
doc.save('invoice.pdf');
}
});
},
error: function(xhr, status, error) {
console.error('Error fetching HTML content:', error);
}
});
});
I haven’t tried anything yet without any ideas. I’m expecting generated invoice to fit in PDF (A4) format.
Maciej is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.