-> In this pdf the content is starting without any top margin, looking for an solution to add top margin.
-> I tried the below code and i'm looking for a solution to add "top_left_margin= 15" to the downloaded pdf file.but the margin is not getting added.
HTML :-
paragraph 1
paragraph 2
paragraph 3
paragraph 4
paragraph 5
SCRIPT:-
const section: any = document.getElementById('summaryId');
var HTML_Width = section.scrollWidth;
var HTML_Height = section.scrollHeight;
var top_left_margin = 35;
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(section, { allowTaint: true }).then(function (canvas) {
var imgData = canvas.toDataURL('image/png');
var imgWidth = 210;
var pageHeight = 299;
var imgHeight = canvas.height * imgWidth / canvas.width;
var heightLeft = imgHeight;
var top_left_margin = 15;
var doc = new jspdf.jsPDF();
var position = 0;
doc.addImage(imgData, 'PNG',top_left_margin, position, imgWidth, imgHeight+30);
heightLeft -= pageHeight;
while (heightLeft >= 0) {
position = heightLeft - imgHeight;
doc.addPage();
doc.addImage(imgData, 'PNG',top_left_margin,position, imgWidth, imgHeight+30);
heightLeft -= pageHeight;
}
doc.save("Dashboard.pdf");
});
}
May be its helpfull