parallax/jsPDF · error · Error
Type of text must be string or Array. "{text}" is not recogn
Error message
Type of text must be string or Array. "{text}" is not recognized. What it means
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.
Source
Thrown at src/jspdf.js:3654
var sa = text.concat();
da = [];
var len = sa.length;
var curDa;
//we do array.join('text that must not be PDFescaped")
//thus, pdfEscape each component separately
while (len--) {
curDa = sa.shift();
if (
typeof curDa !== "string" ||
(Array.isArray(curDa) && typeof curDa[0] !== "string")
) {
tmpTextIsOfTypeString = false;
}
}
textIsOfTypeString = tmpTextIsOfTypeString;
}
if (textIsOfTypeString === false) {
throw new Error(
'Type of text must be string or Array. "' +
text +
'" is not recognized.'
);
}
//If there are any newlines in text, we assume
//the user wanted to print multiple lines, so break the
//text up into an array. If the text is already an array,
//we assume the user knows what they are doing.
//Convert text into an array anyway to simplify
//later code.
if (typeof text === "string") {
if (text.match(/[\r?\n]/)) {
text = text.split(/\r\n|\r|\n/g);
} else {
text = [text];View on GitHub (pinned to a3930ce03a)
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.
Example fix
// before pdf.text(record.age, x, y); // age is a number -> not recognized // after pdf.text(String(record.age), x, y);
Defensive patterns
Strategy: type-guard
Validate before calling
function normalizeText(t) {
if (typeof t === 'string') return t;
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)); });
return String(t);
}
pdf.text(normalizeText(text), x, y); Type guard
function isRecognizedText(t) {
if (typeof t === 'string') return true;
if (Array.isArray(t)) return t.every(function (e) { return typeof e === 'string' || (Array.isArray(e) && typeof e[0] === 'string'); });
return false;
} Prevention
- 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().
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid arguments passed to jsPDF.text
- Unrecognized alignment option, use "left", "center", "right"
- Invalid arguments passed to jsPDF.lines
- Invalid arguments passed to jsPDF.setLineDash
- Invalid argument passed to jsPDF.setCharSpace
AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13).
Data as JSON: /api/errors/46cd73622b5572e0.
Report an issue: GitHub.