问问题
7981 次
2 回答
3
问题在于函数中的条件createCard
。您必须更改对 y 偏移的实际当前值的测试。
看到这个小提琴:https ://jsfiddle.net/jodfkz59/8/
var data = [{
"Name": "Ronan",
"Email": "sodales.elit@eratSed.co.uk",
"Company": "Malesuada Malesuada Ltd"
}, {
"Name": "Calvin",
"Email": "amet.nulla@Vestibulumante.ca",
"Company": "Donec Egestas Foundation"
}, {
"Name": "Kane",
"Email": "Duis.mi@consectetueradipiscingelit.net",
"Company": "Arcu Institute"
}, {
"Name": "Kasper",
"Email": "magna.Phasellus.dolor@velconvallisin.co.uk",
"Company": "Tempor LLP"
}];
var doc = new jsPDF('p', 'pt', 'a4');
//Dimension of A4 in pts: 595 × 842
var pageWidth = 595;
var pageHeight = 842;
var y=500;
var pageMargin = 10;
pageWidth -= pageMargin * 2;
pageHeight -= pageMargin * 2;
var cellMargin = 5;
var cellWidth = 250;
var cellHeight = 60;
var startX = pageMargin;
var startY = pageMargin;
function createCard(item) {
// doc.getTextDimensions(item.Name); turncate or split string if you needed
if (startY >= pageHeight)
{
doc.addPage();
startY = pageMargin // Restart height position
}
doc.text(item.Name, startX, startY);
doc.text(item.Email, startX, startY + 20);
doc.text(item.Company, startX, startY + 40);
var nextPosX = startX + cellWidth + cellMargin;
if (nextPosX > pageWidth) {
startX = pageMargin;
startY += cellHeight;
} else {
startX = nextPosX;
}
}
for (var i = 0; i < data.length; i++) {
createCard(data[i]);
}
于 2017-03-21T18:22:35.993 回答
1
使用“startY”并添加1000,它会自动推送到新页面
doc.autoTable({html:"#exportfrontpageTable",startY:doc.autoTable.previous.finalY + 1115});
于 2020-09-16T10:25:14.247 回答