parallax/jsPDF · error · Error
Invalid value "{value}" for attribute Q supplied.
Error message
Invalid value "{value}" for attribute Q supplied. What it means
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').
Source
Thrown at src/modules/acroform.js:1641
}
}
});
var _Q = null;
Object.defineProperty(this, "Q", {
enumerable: true,
configurable: false,
get: function() {
if (_Q === null) {
return undefined;
}
return _Q;
},
set: function(value) {
if ([0, 1, 2].indexOf(value) !== -1) {
_Q = value;
} else {
throw new Error(
'Invalid value "' + value + '" for attribute Q supplied.'
);
}
}
});
/**
* (Optional; inheritable) A code specifying the form of quadding (justification) that shall be used in displaying the text:
* 'left', 'center', 'right'
*
* @name AcroFormField#textAlign
* @default 'left'
* @type {string}
*/
Object.defineProperty(this, "textAlign", {
get: function() {
var result;
switch (_Q) {View on GitHub (pinned to a3930ce03a)
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
Example fix
// before field.Q = 'left'; // throws field.Q = 3; // throws // after field.textAlign = 'left'; // recommended: accepts strings field.Q = 0; // or use integer directly
Defensive patterns
Strategy: validation
Validate before calling
// Validate Q value before assignment
function setQuadding(field, value) {
var q = Number(value);
if ([0, 1, 2].indexOf(q) === -1) {
throw new RangeError('Q must be 0 (left), 1 (center), or 2 (right), got: ' + value);
}
field.Q = q;
} Type guard
// Prefer textAlign which accepts strings
function isValidQuadding(value) {
return [0, 1, 2].includes(Number(value));
} Try / catch
try {
field.Q = value;
} catch (e) {
// Fall back to textAlign which is more lenient
field.textAlign = String(value);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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/1bc814e92580517f.
Report an issue: GitHub.