parallax/jsPDF · error · Error
Invalid argument passed to jsPDF.__acroform__.arrayToPdfArra
Error message
Invalid argument passed to jsPDF.__acroform__.arrayToPdfArray
What it means
Thrown by arrayToPdfArray when its first argument is not an array. This helper serializes a JavaScript array into a PDF array literal '[...]' for AcroForm field properties (e.g. Opt lists); if the value is not an array it cannot produce valid PDF array syntax and aborts. Exposed at jsPDF.API.__acroform__.arrayToPdfArray.
Source
Thrown at src/modules/acroform.js:775
case "number":
case "object":
content += array[i].toString();
break;
case "string":
if (array[i].substr(0, 1) === "/") {
content += "/" + pdfEscapeName(array[i].substr(1));
} else {
if (typeof objId !== "undefined" && scope)
encryptor = scope.internal.getEncryptor(objId);
content += "(" + pdfEscape(encryptor(array[i].toString())) + ")";
}
break;
}
}
content += "]";
return content;
}
throw new Error(
"Invalid argument passed to jsPDF.__acroform__.arrayToPdfArray"
);
});
function getMatches(string, regex, index) {
index || (index = 1); // default to the first capturing group
var matches = [];
var match;
while ((match = regex.exec(string))) {
matches.push(match[index]);
}
return matches;
}
var pdfArrayToStringArray = function(array) {
var result = [];
if (typeof array === "string") {
result = getMatches(array, /\((.*?)\)/g);
}View on GitHub (pinned to a3930ce03a)
Solutions
- Ensure array-typed AcroForm properties receive actual JavaScript arrays.
- Wrap scalar values in an array before assignment (e.g. [value]).
- Validate with Array.isArray before setting the property.
Example fix
// before field.Opt = 'Choice A'; // string -> arrayToPdfArray throws on output // after field.Opt = ['Choice A', 'Choice B'];
Defensive patterns
Strategy: validation
Validate before calling
function asPdfArray(value) {
if (!Array.isArray(value)) {
throw new Error('Expected an array for PDF array serialization, got ' + typeof value);
}
return jsPDF.API.__acroform__.arrayToPdfArray(value, objId, scope);
} Type guard
function isPdfArrayValue(v) {
return Array.isArray(v);
} Try / catch
try {
content = arrayToPdfArray(value, objId, scope);
} catch (e) {
if (/arrayToPdfArray/.test(e.message)) {
content = arrayToPdfArray([value], objId, scope); // wrap scalar
} else throw e;
} Prevention
- Always set array-typed AcroForm properties (Opt, etc.) to real arrays.
- Wrap single values in an array before assignment.
- Validate with Array.isArray before setting list properties.
When it happens
Trigger: Setting an AcroForm field property that the serializer expects to be an array (e.g. a choice field's Opt) to a non-array value (string, number, object); or calling arrayToPdfArray directly with a scalar.
Common situations: Assigning field.Opt = 'Option1' (a string) instead of field.Opt = ['Option1','Option2']; passing a single value where a list is required; a computed value that returned undefined/null.
Related errors
- Invalid arguments passed to jsPDF.API.__acroform__.setBit
- Invalid arguments passed to jsPDF.API.__acroform__.clearBit
- Invalid arguments passed to jsPDF.API.__acroform__.getBit
- Invalid arguments passed to jsPDF.API.__acroform__.getBitFor
- Invalid arguments passed to jsPDF.API.__acroform__.setBitFor
AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13).
Data as JSON: /api/errors/422865c2dace6c59.
Report an issue: GitHub.