Hopding / pdf-lib

Create and modify PDF documents in any JavaScript environment
https://pdf-lib.js.org
MIT License
6.6k stars 635 forks source link

drawText does not render multiple sequential line breaks. #1580

Open ryangriggs opened 7 months ago

ryangriggs commented 7 months ago

What were you trying to do?

Rendering text such as:

let text = `Hello world
this is the second line

and there is space before this line`;

page.drawText(text, { font: timesRoman,
                    size: 12,
                    lineHeight: timesRoman.heightAtSize(12) +  3,
                    x: 88.56, // 1.23" from left
                    y: 648, // 1" from top
                    maxWidth: 434.88,   // 1.23" margin on each side
});

Would render:

Hello world
this is the second line
and there is space before this line

(the extra \n or \r\n lines are ignored)

A workaround is to type an invisible character (a Space) on each blank line. This would force the new lines to be rendered.

How did you attempt to do it?

See above.

What actually happened?

The multiple \r\n lines were ignored.

What did you expect to happen?

Each blank line containing only \r\n should move the pointer down a full line.

How can we reproduce the issue?

see the above example.

Version

latest

What environment are you running pdf-lib in?

Node

Checklist

Additional Notes

No response