parallax/jsPDF · error · Error

Unrecognized alignment option, use "left", "center", "right"

Error message

Unrecognized alignment option, use "left", "center", "right" or "justify".

What it means

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.

Source

Thrown at src/jspdf.js:3972

        len = da.length;
        maxWidth = maxWidth !== 0 ? maxWidth : pageWidth;
        for (var l = 0; l < len; l++) {
          newY = l === 0 ? getVerticalCoordinate(y) : -leading;
          newX = l === 0 ? getHorizontalCoordinate(x) : 0;

          const numSpaces = da[l].split(" ").length - 1;
          const spacing =
            numSpaces > 0 ? (maxWidth - lineWidths[l]) / numSpaces : 0;

          if (l < len - 1) {
            wordSpacingPerLine.push(hpf(scale(spacing)));
          } else {
            wordSpacingPerLine.push(0);
          }
          text.push([da[l], newX, newY]);
        }
      } else {
        throw new Error(
          'Unrecognized alignment option, use "left", "center", "right" or "justify".'
        );
      }
    }

    //R2L
    var doReversing = typeof options.R2L === "boolean" ? options.R2L : R2L;
    if (doReversing === true) {
      text = processTextByFunction(text, function(text, posX, posY) {
        return [
          text
            .split("")
            .reverse()
            .join(""),
          posX,
          posY
        ];
      });

View on GitHub (pinned to a3930ce03a)

Solutions

  1. Use one of: 'left', 'center', 'right', 'justify'.
  2. Map 'middle'/'start'/'end' from your UI layer to a supported value before calling text().
  3. Lowercase and trim the alignment string before passing.

Example fix

// before
pdf.text('Title', x, y, { align: 'middle' }); // throws
// after
pdf.text('Title', x, y, { align: 'center' });
Defensive patterns

Strategy: validation

Validate before calling

const VALID_ALIGN = ['left','center','right','justify'];
function safeAlign(a) {
  const v = String(a || '').trim().toLowerCase();
  return VALID_ALIGN.includes(v) ? v : 'left';
}
pdf.text('Title', x, y, { align: safeAlign(options.align) });

Type guard

function isValidAlign(a) { return ['left','center','right','justify'].includes(a); }

Prevention

When it happens

Trigger: Passing `{ align: 'middle' }`, `{ align: 'Justify' }` (wrong case), `{ align: 'start' }`, or an unsupported custom alignment string to text().

Common situations: 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.

Related errors


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