Angular2 + jspdf-autotable linebreak不起作用

时间:2017-05-17 13:17:31

标签: angular jspdf jspdf-autotable

我只想在我的评论栏中使用溢出:"换行符" 选项,这是我的代码

 var columns = [
        { title: "Date", dataKey: "date" },
        { title: "User", dataKey: "user" },
        { title: "Issue", dataKey: "issue" },
        { title: "Hours", dataKey: "hours" },
        { title: "Comment", dataKey: "comment" }

    ];
    var rows = [];
    for (let i = 0; i < this.reports.length; i++) {
        var element = {
            date: 5,
            user: 5,
            issue: 3,
            hours: 2,
            comment:"dsfsudihfusidfhsyudfyhdysuyfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
        };
        rows.push(element);
    }
    var options = {
        overflow: "linebreak"
    }
    var doc = new jsPDF();
    doc.autoTable(columns, rows, {
        startY: doc.autoTable.previous.finalY + 15,
        margin: { horizontal: 7 },
        bodyStyles: { valign: 'top' },
        styles: { overflow: 'linebreak', columnWidth: 'wrap' },
        columnStyles: { text: { columnWidth: 'auto' } }
    });
    doc.save('table.pdf');

我从他们的示例文件https://github.com/simonbengtsson/jsPDF-AutoTable/blob/master/examples/examples.js

中复制了此解决方案

但是当我生成我的pdf时,它就像那样 enter image description here

1 个答案:

答案 0 :(得分:1)

尝试将columnStyles: { text: { columnWidth: 'auto' } }更改为columnStyles: { comment: { columnWidth: 'auto' } }