javascript - jsPDF autotable右对齐x位置错误

标签 javascript pdf-generation jspdf jspdf-autotable

我的示例(只需单击“导出 PDF”):https://jsfiddle.net/j9vaqpnz/7/

我的示例导出我的表格,如下所示:

enter image description here .

然后使用库将表格导出为 pdf jspdfautotable .

在导出函数期间,我使用“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 中,我右对齐的所有列都定位不正确,看起来像这样:

enter image description here

这是一个错误吗?或者我没有正确使用“drawCell”?

最佳答案

当使用“didParseCell”(v3.x)时,右对齐正确定位元素。

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

新代码:

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

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

关于javascript - jsPDF autotable右对齐x位置错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41933897/

相关文章:

javascript - React.createRef() 实际上是如何工作的?

java - 如何使用 IText 添加表格而不发生异常?

java - 从 docx 模板生成文档并转换为 PDF - 文本相互重叠

angular - 我不能在Angular 10中使用jsPDF

jsPDF分页符

javascript - 从机器人中隐藏 URL 的方法(类似于 tripadvisor.com)

javascript - 使用 JavaScript 进行印度货币验证的正则表达式

javascript - Rails Bootstrap Active 类(带排序)

c# - 使用 ExpertPDF 从 HTML 生成的 PDF 的质量差异

javascript - IE 使用 html2canvas 返回空/空白 Canvas