0

我正在使用 .pdf 在 pdf 中打印数据jspdf-autotable。我有两种类型的字符串:

  1. 细绳
  2. (5 个空格)+ 字符串

如果 Type(2) 字符串太长,则意味着字符串的剩余部分将打印在下一行(因为我使用的是换行选项)。我所期望的是,打印在下一行的剩余字符串应该与第一个打印相同的 5 个空格。但它打印时没有任何空白。请注意,我没有使用 html,只有 javascript 和 jspdf。如何在每个新行上实现相同的缩进(相同数量的空白)?

实际输出:

    Trees are in proper shape and labeled
appropriately

我想要的是:

  Trees are in proper shape and labeled
  appropriately
4

1 回答 1

0

你有两个选择。

第一个是cellPadding选项。它将在单元格的两侧产生相同的水平空间。

var doc = new jsPDF('p', 'pt');
doc.autoTable(columns, data, {
    styles: {cellPadding: 10}
});
return doc;

另一种选择是使用drawCell钩子并自己决定在哪里打印单元格内容。我没有对此进行测试,但应该可以。

var doc = new jsPDF('p', 'pt');
doc.autoTable(columns, data, {
    drawCell: function (cell, data) {
        if (cell.dataKey === "email") {
            cell.x += 20;
        }
    }
});
return doc;
于 2016-08-10T15:06:45.577 回答