{"record":{"id":"1bc814e92580517f","repo":"parallax/jsPDF","slug":"invalid-value-value-for-attribute-q-supplied","errorCode":null,"errorMessage":"Invalid value \"{value}\" for attribute Q supplied.","messagePattern":"Invalid value \"(.+?)\" for attribute Q supplied\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/modules/acroform.js","lineNumber":1641,"sourceCode":"      }\n    }\n  });\n\n  var _Q = null;\n  Object.defineProperty(this, \"Q\", {\n    enumerable: true,\n    configurable: false,\n    get: function() {\n      if (_Q === null) {\n        return undefined;\n      }\n      return _Q;\n    },\n    set: function(value) {\n      if ([0, 1, 2].indexOf(value) !== -1) {\n        _Q = value;\n      } else {\n        throw new Error(\n          'Invalid value \"' + value + '\" for attribute Q supplied.'\n        );\n      }\n    }\n  });\n\n  /**\n   * (Optional; inheritable) A code specifying the form of quadding (justification) that shall be used in displaying the text:\n   * 'left', 'center', 'right'\n   *\n   * @name AcroFormField#textAlign\n   * @default 'left'\n   * @type {string}\n   */\n  Object.defineProperty(this, \"textAlign\", {\n    get: function() {\n      var result;\n      switch (_Q) {","sourceCodeStart":1623,"sourceCodeEnd":1659,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/modules/acroform.js#L1623-L1659","documentation":"The Q attribute on an AcroFormField controls text quadding (justification) in PDF form fields. The setter only accepts integer values 0 (left-justify), 1 (center), or 2 (right-justify), matching the PDF specification's Q entry. Any other value throws because it would produce a non-spec-compliant PDF that renders incorrectly or fails validation in strict readers. Use the textAlign property instead if you prefer string values ('left', 'center', 'right').","triggerScenarios":"Assigning field.Q = 3, field.Q = -1, field.Q = 'left', or field.Q = 1.5. The setter at acroform.js:1638 uses [0, 1, 2].indexOf(value) which is a strict equality check, so string '1' or float 1.0 will also fail since indexOf uses ===. Only exact integer 0, 1, or 2 pass.","commonSituations":"Developers reading PDF spec docs and passing the string equivalents. TypeScript users whose types allow string but the runtime requires integer. Passing a value from an untrusted form submission or config file without normalization.","solutions":["Use the textAlign property instead: field.textAlign = 'center' which internally maps to Q=1 and accepts string inputs","If setting Q directly, ensure the value is a strict integer 0, 1, or 2: field.Q = parseInt(value, 10)","Validate before assignment: if ([0,1,2].includes(Number(value))) field.Q = Number(value)","Check that no intermediate code converts the integer to a string before assignment"],"exampleFix":"// before\nfield.Q = 'left'; // throws\nfield.Q = 3;        // throws\n\n// after\nfield.textAlign = 'left'; // recommended: accepts strings\nfield.Q = 0;              // or use integer directly","handlingStrategy":"validation","validationCode":"// Validate Q value before assignment\nfunction setQuadding(field, value) {\n  var q = Number(value);\n  if ([0, 1, 2].indexOf(q) === -1) {\n    throw new RangeError('Q must be 0 (left), 1 (center), or 2 (right), got: ' + value);\n  }\n  field.Q = q;\n}","typeGuard":"// Prefer textAlign which accepts strings\nfunction isValidQuadding(value) {\n  return [0, 1, 2].includes(Number(value));\n}","tryCatchPattern":"try {\n  field.Q = value;\n} catch (e) {\n  // Fall back to textAlign which is more lenient\n  field.textAlign = String(value);\n}","preventionTips":["Use field.textAlign instead of field.Q for string-friendly API","Always parseInt the value before assigning to Q","Document that Q accepts only integers 0-2 in your wrapper functions"],"tags":["acroform","validation","pdf-spec","field-properties"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}