jsPDF autoTable columnWidth中总结削减表关闭

问题描述 投票:1回答:1

我使用jsPDF生成HTML表格PDF格式,并jsPDF是伟大的,希望我有一个问题,当我尝试换columnWidth时,我的表被切断:(

var doc = new jsPDF('l', 'mm', "a0");
var tbl = $('#cost-matrix-table').clone();
tbl.find('tr:nth-child(1)').remove();
tbl.find('tr:nth-child(1)').remove();
tbl.find('tr:nth-child(2)').remove();
var res = doc.autoTableHtmlToJson(tbl.get(0));

doc.autoTable(res.columns, res.data, {
    startY: 40,
    margin: {
        top: 40
    },
    addPageContent: function (data) {
        doc.setFontSize(28);
        doc.setTextColor(0);
        doc.setFontStyle('bold');
        doc.text("Losani Homes Cost Matrix " + $("#dropdown").val(), 500, 30);
    },
    styles: {
        fontSize: 20,
        overflow: 'linebreak',
        columnWidth: 'wrap',
    },
    theme: 'grid'
});

doc.save("Report.pdf");

是否有一个解决方案?

javascript jquery jspdf jspdf-autotable
1个回答
1
投票

更换你autotable创作部分为下面的代码

doc.autoTable(res.columns, res.data, {
        startY: 40,
        margin: {
            top: 40
        },
    addPageContent: function (data) {
doc.setFontSize(28);
doc.setTextColor(0);
doc.setFontStyle('bold');
doc.text("Losani Homes Cost Matrix " + $("#dropdown").val(), 500, 30);
},
styles: {
fontSize: 20,
overflow: 'linebreak'
},
columnWidth: 'wrap',
columnStyles:{
0: {
    columnWidth: '100'
},
1: {
    columnWidth: '100'
}, 
2: {
    columnWidth:'100'
},
3: {
    columnWidth: '150'
},
4: {
    columnWidth: '100'
}
},
theme: 'grid'
});
© www.soinside.com 2019 - 2024. All rights reserved.