question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Justified text sometimes expands past maxWidth

See original GitHub issue

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');

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bwl21commented, Feb 20, 2020

this seems to be a bug.

You can reproduce and playaround this in Live Demo.

if you add a space to the string, it works well.

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'
});
0reactions
SimonPrinscommented, Sep 24, 2021

@simonbengtsson @HackbrettXXX I believe this can be closed now. This is what the example looks like in the playaround: justified-fix

I believe this PR fixed it: https://github.com/parallax/jsPDF/pull/3168 Which was released with the 2.4.0 release

Read more comments on GitHub >

github_iconTop Results From Across the Web

Justified text sometimes expands past maxWidth #2553 - GitHub
Sometimes when drawing text with the justify alignment option set the text expands past maxWidth. Red lines in the below example highlights ...
Read more >
Android TextView Justify Text - Stack Overflow
UPDATE 2018-01-01: Android 8.0+ supports justification modes with TextView . ... (or simply "Justification", as it is sometimes ambiguously referred to).
Read more >
5 Ways to Not Over Stretch the Last Line of a Justified Paragraph
Check the “Don't expand character spaces on a line that ends with SHIFT-RETURN” box and click “OK”.
Read more >
Handling Long and Unexpected Content in CSS
Notice how increasing the padding creates a safe area for the icon. Now we can be sure that it won't break if the...
Read more >
How do i get my paragraphs to be perfectly aligned, and ...
My paragraphs look great in a mobile version but loose there alignment when the browser is expanded. I want my paragraphs to be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found