jsPDF使用rowspans从html表生成pdf

时间:2018-02-02 11:59:24

标签: javascript jspdf

我正在尝试使用jsPDF从html表生成pdf。由于不支持rowspan,我试图覆盖drawCell函数,如官方github:https://github.com/simonbengtsson/jsPDF-AutoTable/blob/master/examples/examples.js#L258中的示例所示。这是代码:

`
    drawCell: function (cell, data) {
        let rowspan = null;
        let text = '';
        if(cell.raw !== undefined){
          rowspan = cell.raw.getAttribute('rowspan');
          text = cell.raw.innerText;
        }
        if (rowspan === null || cell.raw === undefined) {
          rowspan = 1;
        }
        console.log(cell);
        doc.rect(cell.x, cell.y, data.table.width, cell.height * rowspan, 'S');
        doc.autoTableText(text, cell.x + cell.width / 2, cell.y + cell.height * rowspan / 2, {
          halign: 'center',
          valign: 'middle'
        });
        return false;
      }
    });

` 这就是结果:enter image description here

0 个答案:

没有答案