Skip to content

Justified text sometimes expands past maxWidth #2553

@simonbengtsson

Description

@simonbengtsson

Sometimes when drawing text with the justify alignment option set the text expands past maxWidth. Red lines in the below example highlights the maxWidth length and the fillerrrrr word can be seen expanding past it.

Screenshot 2019-08-09 at 14 19 12

The same example works when using left alignment:

Screenshot 2019-08-09 at 14 19 30

Here is the code for the example:

var doc = new jsPDF();

// maxWidth lines
doc.setDrawColor(255, 0, 0);
doc.setLineWidth(0.5);
doc.line(10, 10, 10, 33);
doc.line(60, 10, 60, 33);

doc.text(10, 20, 'filler shortword longerword fillerrrrrr', {
    maxWidth: 50,
    align: 'justify'
});

doc.save('table.pdf');

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions