2017-01-30 51 views
1

我的例子(只需点击 “导出PDF”):https://jsfiddle.net/j9vaqpnz/7/jsPDF autotable右对齐x位置错误

我的例子出口我的表看起来像这样:

enter image description here

然后使用库jspdfautotable将该表导出为pdf。

在我使用了“drawCell”功能导出功能和它含有许多我右对齐他们如下所有列:

drawCell: function (cell, data) { 
       var col = data.column.index; 
       if(col==3 || col==5 || col==6 || col==7 || col==8 || col==9 || col==10){ 
        cell.styles.halign = 'right'; 
       } 
      } 

问题:在PDF所有我所右对齐的inproperly定位柱,它看起来像这样:

enter image description here

这是一个错误?或者,我可能正在使用“drawCell”吗?

+0

尝试使用,而不是drawCell createdCell。 –

+0

Takk Simon。如果其他人正在寻找这个,我已经发布了一个更新的工作示例以供完成。 – DavidDunham

回答

1

通过使用“createdCell”和“createdHeaderCell”,右对齐可以正确定位元素。

更新例如:https://jsfiddle.net/j9vaqpnz/10/

新代码:

... 
createdHeaderCell: function (cell, data) { 
    alignCol(cell, data); 
}, 
createdCell: function (cell, data) { 
    alignCol(cell, data); 
} 
... 

function alignCol(cell, data){ 
    var col = data.column.index; 
    if(col==3 || col==5 || col==6 || col==7 || col==8 || col==9 || col==10){ 
     cell.styles.halign = 'right'; 
    } 
}