parallax/jsPDF · error · Error

zoom must be Integer (e.g. 2), a percentage Value (e.g. 300%

Error message

zoom must be Integer (e.g. 2), a percentage Value (e.g. 300%) or fullwidth, fullheight, fullpage, original. "{zoom}" is not recognized.

What it means

`setZoomMode` (src/jspdf.js:887) accepts an integer zoom factor, a percentage string like `'300%'`, or one of the named modes `fullwidth`, `fullheight`, `fullpage`, `original` (and undefined/null for default). It throws at src/jspdf.js:904 for anything that matches none of these. The numeric branch uses `!isNaN(zoom)`, so numeric strings are tolerated, but arbitrary strings and out-of-vocabulary names are rejected.

Source

Thrown at src/jspdf.js:904

  var setZoomMode = (API.__private__.setZoomMode = function(zoom) {
    var validZoomModes = [
      undefined,
      null,
      "fullwidth",
      "fullheight",
      "fullpage",
      "original"
    ];

    if (/^(?:\d+\.\d*|\d*\.\d+|\d+)%$/.test(zoom)) {
      zoomMode = zoom;
    } else if (!isNaN(zoom)) {
      zoomMode = parseInt(zoom, 10);
    } else if (validZoomModes.indexOf(zoom) !== -1) {
      zoomMode = zoom;
    } else {
      throw new Error(
        'zoom must be Integer (e.g. 2), a percentage Value (e.g. 300%) or fullwidth, fullheight, fullpage, original. "' +
          zoom +
          '" is not recognized.'
      );
    }
  });

  API.__private__.getZoomMode = function() {
    return zoomMode;
  };

  var pageMode; // default: 'UseOutlines';
  var setPageMode = (API.__private__.setPageMode = function(pmode) {
    var validPageModes = [
      undefined,
      null,
      "UseNone",
      "UseOutlines",

View on GitHub (pinned to a3930ce03a)

Solutions

  1. Use one of the exact tokens: `'fullwidth'`, `'fullheight'`, `'fullpage'`, `'original'` (lowercase).
  2. For a numeric zoom, pass a number or numeric string (e.g. `2` or `'2'`).
  3. For a percentage, use the `'300%'` form with a `%` suffix.
  4. If migrating from another viewer's options, map their vocabulary onto jsPDF's allowed set.

Example fix

// before
 new jsPDF({ zoom: 'fit-width' });  // throws

// after
 new jsPDF({ zoom: 'fullwidth' });
Defensive patterns

Strategy: validation

Validate before calling

var ZOOM_TOKENS = ['fullwidth','fullheight','fullpage','original'];
function normalizeZoom(z) {
  if (z == null) return undefined;
  if (ZOOM_TOKENS.indexOf(z) !== -1) return z;          // named mode
  if (typeof z === 'number' || /^\d+$/.test(String(z))) return parseInt(z, 10); // integer
  if (/^\d+(\.\d+)?%$/.test(String(z))) return z;       // percentage
  return undefined; // unsupported -> use default
}
var zoom = normalizeZoom(userZoom);
if (zoom !== undefined) doc.internal.__private__.setZoomMode(zoom);

Type guard

function isValidZoom(z) {
  if (z == null) return true;
  if (['fullwidth','fullheight','fullpage','original'].indexOf(z) !== -1) return true;
  if (!isNaN(z)) return true;
  return /^\d+(\.\d+)?%$/.test(String(z));
}

Try / catch

try {
  doc.internal.__private__.setZoomMode(zoom);
} catch (e) {
  if (/zoom must be/.test(e.message)) {
    doc.internal.__private__.setZoomMode('fullwidth');  // safe default
  } else throw e;
}

Prevention

When it happens

Trigger: `new jsPDF({ zoom: 'fit' })`; `doc.setZoomMode('200')` is fine (numeric), but `'200x'` throws; `zoom: 'FullWidth'` throws (case-sensitive); passing an object or boolean.

Common situations: Using viewer-specific zoom vocabulary (`'fit'`, `'fit-width'`, `'actual-size'`) that isn't in jsPDF's list; case typos; passing a value meant for a different PDF viewer's API.

Related errors


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