Я добавляю простой текст и изображение логотипа в качестве заголовка в формате PDF с использованием JSPDF.Первая страница работает нормально, но на второй странице сгенерированного pdf содержимое HTML и мой заголовок перекрываются.Мне нужно дать некоторый запас для контента, поступающего из HTML, чтобы заголовок и контент HTML могли быть разделены.
var imgData = "data:image/jpeg;base64" + "," + base64Data;
var pdf = new jsPDF("l", "mm", "legal");
var source = $('#HTMLtoPDF')[0];
var specialElementHandlers = {
'#skipForPDFReport': function (element, renderer) {
return true
}
};
var margins = {
top: 40,
bottom: 60,
left: 40,
width: 200,
};
pdf.fromHTML(
source // HTML string or DOM elem ref.
, margins.left // x coord
, margins.top // y coord
, {
'width': margins.width, // max width of content on PDF,
'elementHandlers': specialElementHandlers,
style: {
fontSize: 5
}
},
function (dispose) {
var totalPages = pdf.internal.getNumberOfPages();
console.log("total", totalPages);
for(var i = totalPages; i >= 1; i--)
{ //make this page, the current page we are currently working on.
pdf.setPage(i);
pdf.addImage(imgData, 'JPEG', 37, 10, 35, 20);
pdf.setFont("helvetica");
pdf.setFontType("bold");
pdf.setFontSize(22);
pdf.setTextColor("#38a4ff");
pdf.text(175, 22, name + " - " + "Report", "center");
pdf.setFontType("normal");
pdf.setFontSize(12);
pdf.text(180, 30, "Report generated on " + Moment().format("MMMM Do YYYY, h:mm:ss a") + " by " + userName, 'center');
pdf.setTextColor("black");
}
// dispose: object with X, Y of the last line add to the PDF
// this allow the insertion of new lines after html
pdf.save('report.pdf');
}
)