jsPDF icon indicating copy to clipboard operation
jsPDF copied to clipboard

charSpace and maxWidth in doc.text() : charSpace > 0 and maxWidth is not respected

Open fmay opened this issue 4 years ago • 4 comments

I have read and understood the contribution guidelines.

Basically, charSpace and maxWidth don't play nicely together.

Code tested using your live demo at http://raw.githack.com/MrRio/jsPDF/master/

The following works fine ...

var doc = new jsPDF();
doc.setFontSize(22);
doc.text("This is a title", 20, 20);

const maxWidth = 100;
const charSpace = 0;

// Drawing a box to show maxWidth clearly
doc.rect(20, 20, maxWidth, 100, 'S')

// Using 'justify' to show things clearly but also happens with 'left'
const options = {
    maxWidth: maxWidth,
    charSpace: charSpace,
    align: 'justify'
}
const str = "Mary had a little lamb she also had a duck. She put them on the mantlepiece to see if they would fall off."

doc.setFontSize(16);
doc.text(str, 20, 30, options);

However, if you change charSpace to 1 then maxWidth is not correctly applied and then text extends beyond the maxWidth boundary.

Screen Shot 2021-10-16 at 07 00 24

I can then adjust maxWidth to try and compensate for this, but the formula is not leaping off the page at me!

fmay avatar Oct 16 '21 06:10 fmay

Thanks for reporting the bug. Pull requests to fix it are welcome ;)

HackbrettXXX avatar Oct 18 '21 09:10 HackbrettXXX

For some reason I didn't get a notification of your response.

I am not sure whether I am skilled enough for it. I'll take a look though.

fmay avatar Oct 21 '21 14:10 fmay

i want to work on this issue

kanisshka avatar Oct 01 '22 02:10 kanisshka

Hey @HackbrettXXX I want to work on this issue( #3299 ) can you assign this to me.

Sa2003hil avatar Oct 04 '23 18:10 Sa2003hil