Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

layoutMultilineText takes a very long time for long strings #1202

Open
2 tasks done
seibar opened this issue Mar 29, 2022 · 0 comments
Open
2 tasks done

layoutMultilineText takes a very long time for long strings #1202

seibar opened this issue Mar 29, 2022 · 0 comments

Comments

@seibar
Copy link

seibar commented Mar 29, 2022

What were you trying to do?

Calling layoutMultilineText to handle wrapping text in my PDFs.

How did you attempt to do it?

First of all, thanks for the fantastic library! 🥇

I'm using layoutMultilineText to handle wrapping text in my PDFs. When passing a long string (thousands of characters), the function takes a very long time to execute. The execution time increases with font size.

I've observed this in multiple Node JS 14.7 environments.

What actually happened?

A string of length 10 thousand is takes over 30 seconds at font size size 12.

What did you expect to happen?

It's reasonable for there to be some upper limit, but I ran into this with a production work load with an actual string entered by a user. I would expect a 10 thousand character string to take no more than a few seconds.

How can we reproduce the issue?

let text = '';
for (let i = 0; i < 2000; i++) {
    text += 'test ';
}

const now = Date.now();

layoutMultilineText(text, {
    alignment: TextAlignment.Left,
    bounds: {
        width: 500,
        height: 500,
        x: 0,
        y: 0
    },
    font,
    fontSize: 12,
});

console.log(Date.now() - now); // 30 to 40 seconds

Version

1.17.1

What environment are you running pdf-lib in?

Node

Checklist

  • My report includes a Short, Self Contained, Correct (Compilable) Example.
  • I have attached all PDFs, images, and other files needed to run my SSCCE.

Additional Notes

Again, thanks for your efforts in maintaining this terrific library!

I believe I have a fix for this and will follow up with a PR.

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

No branches or pull requests

1 participant