{"record":{"id":"aaf42f742c6c2245","repo":"parallax/jsPDF","slug":"unrecognized-alignment-option-use-left-center","errorCode":null,"errorMessage":"Unrecognized alignment option, use \"left\", \"center\", \"right\" or \"justify\".","messagePattern":"Unrecognized alignment option, use \"left\", \"center\", \"right\" or \"justify\"\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/jspdf.js","lineNumber":3972,"sourceCode":"        len = da.length;\n        maxWidth = maxWidth !== 0 ? maxWidth : pageWidth;\n        for (var l = 0; l < len; l++) {\n          newY = l === 0 ? getVerticalCoordinate(y) : -leading;\n          newX = l === 0 ? getHorizontalCoordinate(x) : 0;\n\n          const numSpaces = da[l].split(\" \").length - 1;\n          const spacing =\n            numSpaces > 0 ? (maxWidth - lineWidths[l]) / numSpaces : 0;\n\n          if (l < len - 1) {\n            wordSpacingPerLine.push(hpf(scale(spacing)));\n          } else {\n            wordSpacingPerLine.push(0);\n          }\n          text.push([da[l], newX, newY]);\n        }\n      } else {\n        throw new Error(\n          'Unrecognized alignment option, use \"left\", \"center\", \"right\" or \"justify\".'\n        );\n      }\n    }\n\n    //R2L\n    var doReversing = typeof options.R2L === \"boolean\" ? options.R2L : R2L;\n    if (doReversing === true) {\n      text = processTextByFunction(text, function(text, posX, posY) {\n        return [\n          text\n            .split(\"\")\n            .reverse()\n            .join(\"\"),\n          posX,\n          posY\n        ];\n      });","sourceCodeStart":3954,"sourceCodeEnd":3990,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/jspdf.js#L3954-L3990","documentation":"Thrown by jsPDF.text when the `align` option is not one of the recognized values. Supported alignments are 'left', 'center', 'right', and 'justify'. Any other string (or a value coerced to another string) falls into the else branch and throws.","triggerScenarios":"Passing `{ align: 'middle' }`, `{ align: 'Justify' }` (wrong case), `{ align: 'start' }`, or an unsupported custom alignment string to text().","commonSituations":"Mapping CSS/text-align values (which include 'justify', 'start', 'end') directly into jsPDF; casing mistakes; typos like 'cente'; assuming 'middle' works like in some other libraries.","solutions":["Use one of: 'left', 'center', 'right', 'justify'.","Map 'middle'/'start'/'end' from your UI layer to a supported value before calling text().","Lowercase and trim the alignment string before passing."],"exampleFix":"// before\npdf.text('Title', x, y, { align: 'middle' }); // throws\n// after\npdf.text('Title', x, y, { align: 'center' });","handlingStrategy":"validation","validationCode":"const VALID_ALIGN = ['left','center','right','justify'];\nfunction safeAlign(a) {\n  const v = String(a || '').trim().toLowerCase();\n  return VALID_ALIGN.includes(v) ? v : 'left';\n}\npdf.text('Title', x, y, { align: safeAlign(options.align) });","typeGuard":"function isValidAlign(a) { return ['left','center','right','justify'].includes(a); }","tryCatchPattern":null,"preventionTips":["Map CSS/text-align values to the four supported options before calling.","Lowercase and trim alignment strings from user input.","Default unknown alignments to 'left' in your wrapper."],"tags":["validation","text","alignment","options","api"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}