Skip to content

splitTextToSize method crashes if cell value is not a string #2849

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

Closed
skchawala opened this issue Aug 14, 2020 · 2 comments
Closed

splitTextToSize method crashes if cell value is not a string #2849

skchawala opened this issue Aug 14, 2020 · 2 comments

Comments

@skchawala
Copy link

skchawala commented Aug 14, 2020

`API.splitTextToSize = function(text, maxlen, options) {
"use strict";

 .......

// first we split on end-of-line chars
var paragraphs;
if (Array.isArray(text)) {
  paragraphs = text;
} else {
  paragraphs = text.split(/\r?\n/);
}

.....
})(jsPDF.API)`

this method crashes at this line paragraphs = text.split(/\r?\n/)
if "text" is not a string.
in my case cell value/text can be number also
so 34.split() method causes error.

TypeError: t.split is not a function at Object.xt.splitTextToSize (split_text_to_size.js:360) at Object.<anonymous> (cell.js:567) at Array.map (<anonymous>) at Object.s (cell.js:564) ....

this case should be handled by converting this number to string I think

@HackbrettXXX
Copy link
Collaborator

The table function accepts only strings as cell values. You could preprocess your data and convert the numbers to a string beforehand.

@skchawala
Copy link
Author

skchawala commented Aug 14, 2020

yes. for now I am writing a utility function to convert to string.
would have been easy if could do this paragraphs = `${text}`.split(/\r?\n/);

HackbrettXXX added a commit that referenced this issue Aug 25, 2020
Fix-splitTextToSize method crashes if cell value is not a string #2849
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

2 participants