{"record":{"id":"46cd73622b5572e0","repo":"parallax/jsPDF","slug":"type-of-text-must-be-string-or-array-text-is","errorCode":null,"errorMessage":"Type of text must be string or Array. \"{text}\" is not recognized.","messagePattern":"Type of text must be string or Array\\. \"(.+?)\" is not recognized\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/jspdf.js","lineNumber":3654,"sourceCode":"      var sa = text.concat();\n      da = [];\n      var len = sa.length;\n      var curDa;\n      //we do array.join('text that must not be PDFescaped\")\n      //thus, pdfEscape each component separately\n      while (len--) {\n        curDa = sa.shift();\n        if (\n          typeof curDa !== \"string\" ||\n          (Array.isArray(curDa) && typeof curDa[0] !== \"string\")\n        ) {\n          tmpTextIsOfTypeString = false;\n        }\n      }\n      textIsOfTypeString = tmpTextIsOfTypeString;\n    }\n    if (textIsOfTypeString === false) {\n      throw new Error(\n        'Type of text must be string or Array. \"' +\n          text +\n          '\" is not recognized.'\n      );\n    }\n\n    //If there are any newlines in text, we assume\n    //the user wanted to print multiple lines, so break the\n    //text up into an array. If the text is already an array,\n    //we assume the user knows what they are doing.\n    //Convert text into an array anyway to simplify\n    //later code.\n\n    if (typeof text === \"string\") {\n      if (text.match(/[\\r?\\n]/)) {\n        text = text.split(/\\r\\n|\\r|\\n/g);\n      } else {\n        text = [text];","sourceCodeStart":3636,"sourceCodeEnd":3672,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/jspdf.js#L3636-L3672","documentation":"Thrown by jsPDF.text when the text argument is neither a string nor an array of strings/string-pairs. The code sets textIsOfTypeString by checking that a plain string was given, or that an array's elements are all strings or [string, ...] arrays. If neither shape matches, the unrecognized value is rejected.","triggerScenarios":"Passing a number, object, boolean, or a mixed array (e.g. [123, 'b']) to text(). Also passing a single non-string scalar where a string is expected.","commonSituations":"Forgetting to stringify a numeric field; passing a Date or object directly; mixing numbers into a multi-line text array; reading untyped JSON values into text() without coercion.","solutions":["Coerce scalar values to strings before passing: String(value) or template literals.","For multi-line text, pass an array of strings: ['line1', 'line2'].","If the array contains [string, x, y] entries, keep the first element of each a string."],"exampleFix":"// before\npdf.text(record.age, x, y); // age is a number -> not recognized\n// after\npdf.text(String(record.age), x, y);","handlingStrategy":"type-guard","validationCode":"function normalizeText(t) {\n  if (typeof t === 'string') return t;\n  if (Array.isArray(t)) return t.map(function (e) { return typeof e === 'string' ? e : (Array.isArray(e) ? [String(e[0]), e[1], e[2]] : String(e)); });\n  return String(t);\n}\npdf.text(normalizeText(text), x, y);","typeGuard":"function isRecognizedText(t) {\n  if (typeof t === 'string') return true;\n  if (Array.isArray(t)) return t.every(function (e) { return typeof e === 'string' || (Array.isArray(e) && typeof e[0] === 'string'); });\n  return false;\n}","tryCatchPattern":null,"preventionTips":["Stringify numeric/object values before text().","Keep multi-line arrays homogeneous (all strings or all [string,x,y]).","Validate untyped JSON before feeding it to text()."],"tags":["validation","text","type","array","api"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}