I am using a script to export html to pdf but at the bottom, the page split is no corect. the script below
var HTML_Width = $("#content").width();
var HTML_Height = $("#content").height();
var top_left_margin = 15;
var PDF_Width = HTML_Width + (top_left_margin * 2);
var PDF_Height = (PDF_Width * 1.2) + (top_left_margin * 2);
var canvas_image_width = HTML_Width;
var canvas_image_height = HTML_Height;
var totalPDFPages = Math.ceil(HTML_Height / PDF_Height) - 1;
html2canvas($("#content")[0], { allowTaint: true }).then(function (canvas) {
canvas.getContext('2d');
console.log(canvas.height + " " + canvas.width);
var imgData = canvas.toDataURL("image/jpeg", 1.0);
var pdf = new jsPDF('p', 'pt', [PDF_Width, PDF_Height]);
var options = {pagesplit: true};
pdf.addImage(imgData, 'JPG', top_left_margin, top_left_margin, canvas_image_width, canvas_image_height);
for (var i = 1; i <= totalPDFPages; i++) {
pdf.addPage(PDF_Width, PDF_Height);
pdf.addImage(imgData, 'JPG', top_left_margin, -(PDF_Height * i) + (top_left_margin * 4), canvas_image_width, canvas_image_height);
}
pdf.save("JSA"+"-"+"@Model.JSAMain.JSANo"+".pdf");
});
and a capture from pdf


Marius VasilePosted Aug 29, 2021, 1:05 PM
Sachin SinghPosted Aug 29, 2021, 11:46 AM
var form = $("#content")[0];
var a4 = [595.28, 841.89];
form.width((a4[0] * 1.33333) - 80).css('max-width', 'none');
html2canvas(form, { allowTaint: true }).then(function (canvas) {
canvas.getContext('2d');
var imgWidth = 200;
var pageHeight = 290;
var imgHeight = canvas.height * imgWidth / canvas.width;
var heightLeft = imgHeight;
var doc = new jsPDF('p', 'mm');
var position = 0;
var img = canvas.toDataURL("image/jpeg");
doc.addImage(img, 'JPEG', 0, position, imgWidth, imgHeight);
heightLeft -= pageHeight;
while (heightLeft >= 0) {
position = heightLeft - imgHeight;
doc.addPage();
doc.addImage(img, 'JPEG', 0, position, imgWidth, imgHeight);
heightLeft -= pageHeight;
}
});
doc.save("JSA"+"-"+"@Model.JSAMain.JSANo"+".pdf");
Sachin SinghPosted Aug 29, 2021, 11:00 AM
Marius VasilePosted Aug 29, 2021, 10:48 AM
Sachin SinghPosted Aug 29, 2021, 10:27 AM