Skip to content

doc.getTextWidth does not work properly #3200

Open
@zwingpoint

Description

@zwingpoint

Hello, it looks like for some special text, the getTextWidth does not work properly. Below is an example. As you could see I have added a space between "FILE_VALIDATE_NAME" and "World", but in the generated doc, there is almost no space. Another example below works.

Thanks!

The code could be copied to http://raw.githack.com/MrRio/jsPDF/master/ to reproduce.

var doc = new jsPDF();

var t = "FILE_VALIDATE_NAME";

doc.text(t, 20, 20)

var l = doc.getTextWidth(t);
var sl = doc.getTextWidth(" ");

var startX = 20 + l + sl;

// No space between _NAME and World
doc.text("World", startX, 20)

// below is ok
var t = "FILE";

doc.text(t, 20, 40)

var l = doc.getTextWidth(t);
var sl = doc.getTextWidth(" ");

var startX = 20 + l + sl;

doc.text("World", startX, 40)

Screenshot 2021-07-04 at 23 33 51

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