Skip to content

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

Open
@fmay

Description

@fmay

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!

Activity

HackbrettXXX

HackbrettXXX commented on Oct 18, 2021

@HackbrettXXX
Collaborator

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

fmay

fmay commented on Oct 21, 2021

@fmay
Author

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.

kanisshka

kanisshka commented on Oct 1, 2022

@kanisshka

i want to work on this issue

Sa2003hil

Sa2003hil commented on Oct 4, 2023

@Sa2003hil

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @fmay@HackbrettXXX@kanisshka@Sa2003hil

        Issue actions

          charSpace and maxWidth in doc.text() : charSpace > 0 and maxWidth is not respected · Issue #3299 · parallax/jsPDF