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

  1. Use the textAlign property instead: field.textAlign = 'center' which internally maps to Q=1 and accepts string inputs
  2. If setting Q directly, ensure the value is a strict integer 0, 1, or 2: field.Q = parseInt(value, 10)
  3. Validate before assignment: if ([0,1,2].includes(Number(value))) field.Q = Number(value)
  4. 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

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


AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13). Data as JSON: /api/errors/1bc814e92580517f. Report an issue: GitHub.