{"record":{"id":"422865c2dace6c59","repo":"parallax/jsPDF","slug":"invalid-argument-passed-to-jspdf-acroform-arra","errorCode":null,"errorMessage":"Invalid argument passed to jsPDF.__acroform__.arrayToPdfArray","messagePattern":"Invalid argument passed to jsPDF\\.__acroform__\\.arrayToPdfArray","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/modules/acroform.js","lineNumber":775,"sourceCode":"        case \"number\":\n        case \"object\":\n          content += array[i].toString();\n          break;\n        case \"string\":\n          if (array[i].substr(0, 1) === \"/\") {\n            content += \"/\" + pdfEscapeName(array[i].substr(1));\n          } else {\n            if (typeof objId !== \"undefined\" && scope)\n              encryptor = scope.internal.getEncryptor(objId);\n            content += \"(\" + pdfEscape(encryptor(array[i].toString())) + \")\";\n          }\n          break;\n      }\n    }\n    content += \"]\";\n    return content;\n  }\n  throw new Error(\n    \"Invalid argument passed to jsPDF.__acroform__.arrayToPdfArray\"\n  );\n});\n\nfunction getMatches(string, regex, index) {\n  index || (index = 1); // default to the first capturing group\n  var matches = [];\n  var match;\n  while ((match = regex.exec(string))) {\n    matches.push(match[index]);\n  }\n  return matches;\n}\nvar pdfArrayToStringArray = function(array) {\n  var result = [];\n  if (typeof array === \"string\") {\n    result = getMatches(array, /\\((.*?)\\)/g);\n  }","sourceCodeStart":757,"sourceCodeEnd":793,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/modules/acroform.js#L757-L793","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nfield.Opt = 'Choice A'; // string -> arrayToPdfArray throws on output\n\n// after\nfield.Opt = ['Choice A', 'Choice B'];","handlingStrategy":"validation","validationCode":"function asPdfArray(value) {\n  if (!Array.isArray(value)) {\n    throw new Error('Expected an array for PDF array serialization, got ' + typeof value);\n  }\n  return jsPDF.API.__acroform__.arrayToPdfArray(value, objId, scope);\n}","typeGuard":"function isPdfArrayValue(v) {\n  return Array.isArray(v);\n}","tryCatchPattern":"try {\n  content = arrayToPdfArray(value, objId, scope);\n} catch (e) {\n  if (/arrayToPdfArray/.test(e.message)) {\n    content = arrayToPdfArray([value], objId, scope); // wrap scalar\n  } else throw e;\n}","preventionTips":["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."],"tags":["acroform","validation","serialization"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}