diff --git a/src/modules/cell.js b/src/modules/cell.js index c044670ad..40a783233 100644 --- a/src/modules/cell.js +++ b/src/modules/cell.js @@ -188,9 +188,13 @@ import { jsPDF } from "../jspdf.js"; var tempWidth = 0; if (!Array.isArray(text) && typeof text !== "string") { - throw new Error( - "getTextDimensions expects text-parameter to be of type String or an Array of Strings." - ); + if (typeof text === "number") { + text = String(text); + } else { + throw new Error( + "getTextDimensions expects text-parameter to be of type String or type Number or an Array of Strings." + ); + } } const maxWidth = options.maxWidth; diff --git a/src/modules/split_text_to_size.js b/src/modules/split_text_to_size.js index e87005d5d..fed4fdbec 100755 --- a/src/modules/split_text_to_size.js +++ b/src/modules/split_text_to_size.js @@ -357,7 +357,7 @@ import { jsPDF } from "../jspdf.js"; if (Array.isArray(text)) { paragraphs = text; } else { - paragraphs = text.split(/\r?\n/); + paragraphs = String(text).split(/\r?\n/); } // now we convert size (max length of line) into "font size units" diff --git a/test/specs/cell.spec.js b/test/specs/cell.spec.js index 8f7091d53..0a011a982 100644 --- a/test/specs/cell.spec.js +++ b/test/specs/cell.spec.js @@ -34,7 +34,7 @@ describe("Module: Cell", () => { doc.getTextDimensions(); }).toThrow( new Error( - "getTextDimensions expects text-parameter to be of type String or an Array of Strings." + "getTextDimensions expects text-parameter to be of type String or type Number or an Array of Strings." ) ); });