【发布时间】:2021-07-23 13:00:33
【问题描述】:
我正在尝试动态获取使用 jsPDF 和 js Autotable 创建的 PDF 中表格的高度。我想在表格下方添加一行文字,但是由于表格高度发生变化,我无法为文字行放置特定的Y值。
我当前的表格脚本:
let col = ['Header 1', 'Header 2', 'Header 3']
let rows = arrayForTable;
let getTableWidth = 150;
let pageWidth = doc.internal.pageSize.width;
let tableMargin = (pageWidth - getTableWidth) / 2;
let height = 0;
doc.autoTable(col, rows, {
margin: {top: 20, right: tableMargin, left: tableMargin},
startY: 70,
styles: {
halign: 'center',
overflow: 'linebreak',
cellWidth: 'wrap',
valign: 'middle'
},
columnStyles: {
0: {cellWidth: 50},
1: {cellWidth: 50},
2: {cellWidth: 50},
},
headStyles: {
fillColor: [163, 32, 32]
},
didParseCell: function(data) {
if (data.row.index === rows.length - 1) {
data.cell.styles.fillColor = [63, 63, 64];
data.cell.styles.fontStyle = 'bold';
data.cell.styles.textColor = [255, 255, 255];
}
height = data.table.height
}
});
console.log(height)
控制台打印未定义。任何人都知道如何在此表下动态添加一行文本,而不必像这样指定静态 Y 值:
doc.text(25, 40, exampleText);
由于显示的数据不同,表格高度每次都会变化。
我正在使用 jsPDF AutoTable 插件 v3.5.6。
【问题讨论】:
标签: jspdf jspdf-autotable