Skip to content

jsPDFAPI.cell method does not correctly align values in table when aligning them to the right side #580

@irepela

Description

@irepela

I'm using jsPDFAPI.cell to align table vaues to the right side but it doesn't align them correctly
and the problem is with calculating text width. This is the code in jsPDF:

if (align === 'right') {
                if (txt instanceof Array) {
                    for(var i = 0; i<txt.length; i++) {
                        var currentLine = txt[i];
                        var textSize = this.getStringUnitWidth(currentLine) * this.internal.getFontSize();
                        this.text(currentLine, x + w - textSize - padding, y + this.internal.getLineHeight()*(i+1));
                    }
                }
            }

It can be easily fixed by changing line which calculates text width to:

var textSize = this.getStringUnitWidth(currentLine) * this.internal.getFontSize() / this.internal.scaleFactor;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions