parallax/jsPDF · error · Error

Layout mode must be one of continuous, single, twoleft, twor

Error message

Layout mode must be one of continuous, single, twoleft, tworight. "{layout}" is not recognized.

What it means

`setLayoutMode` (src/jspdf.js:942) sets the viewer's page layout. The allowed values (plus undefined/null) are `continuous`, `single`, `twoleft`, `tworight`, and `two` — case-sensitive. It throws at src/jspdf.js:953 for anything else. These map to the PDF spec's PageLayout entry (e.g. TwoColumnLeft → twoleft).

Source

Thrown at src/jspdf.js:954

  API.__private__.getPageMode = function() {
    return pageMode;
  };

  var layoutMode; // default: 'continuous';
  var setLayoutMode = (API.__private__.setLayoutMode = function(layout) {
    var validLayoutModes = [
      undefined,
      null,
      "continuous",
      "single",
      "twoleft",
      "tworight",
      "two"
    ];

    if (validLayoutModes.indexOf(layout) == -1) {
      throw new Error(
        'Layout mode must be one of continuous, single, twoleft, tworight. "' +
          layout +
          '" is not recognized.'
      );
    }
    layoutMode = layout;
  });

  API.__private__.getLayoutMode = function() {
    return layoutMode;
  };

  /**
   * Set the display mode options of the page like zoom and layout.
   *
   * @name setDisplayMode
   * @memberof jsPDF#
   * @function

View on GitHub (pinned to a3930ce03a)

Solutions

  1. Use jsPDF's aliases exactly: `'continuous'`, `'single'`, `'twoleft'`, `'tworight'`, `'two'`.
  2. Map spec/viewer vocabulary to these aliases in a config layer.
  3. For default, pass undefined/null or omit the call.

Example fix

// before
 doc.setLayoutMode('TwoColumnLeft');  // spec name, throws

// after
 doc.setLayoutMode('twoleft');
Defensive patterns

Strategy: validation

Validate before calling

var LAYOUT_MODES = ['continuous','single','twoleft','tworight','two'];
function safeLayoutMode(m) {
  return LAYOUT_MODES.indexOf(m) !== -1 ? m : undefined;
}
var lm = safeLayoutMode(userLayout);
if (lm) doc.internal.__private__.setLayoutMode(lm);

Type guard

function isValidLayoutMode(m) {
  return m == null || ['continuous','single','twoleft','tworight','two'].indexOf(m) !== -1;
}

Try / catch

try {
  doc.internal.__private__.setLayoutMode(layout);
} catch (e) {
  if (/Layout mode must be/.test(e.message)) {
    doc.internal.__private__.setLayoutMode('continuous');  // safe default
  } else throw e;
}

Prevention

When it happens

Trigger: `doc.setLayoutMode('onepage')`; `'TwoColumnLeft'` (the spec name, not jsPDF's alias); `'scroll'`; `'continuous-scroll'`; any lowercase/typo variant of the allowed set.

Common situations: Using raw PDF-spec names (TwoColumnLeft/TwoPageRight) instead of jsPDF's aliases; viewer-specific layout strings; case typos.

Related errors


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