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
- Use one of the exact tokens: `'fullwidth'`, `'fullheight'`, `'fullpage'`, `'original'` (lowercase).
- For a numeric zoom, pass a number or numeric string (e.g. `2` or `'2'`).
- For a percentage, use the `'300%'` form with a `%` suffix.
- 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
- Use only the documented tokens (lowercase) or a numeric/percentage value.
- Map viewer-specific vocabulary onto jsPDF's allowed set in a config layer.
- Avoid free-text zoom strings from user input.
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
- Page mode must be one of UseNone, UseOutlines, UseThumbs, or
- Layout mode must be one of continuous, single, twoleft, twor
- Invalid unit: {unit}
- Invalid format: ${format}
- Invalid arguments passed to PubSub.subscribe (jsPDF-module)
AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13).
Data as JSON: /api/errors/d7f381b83a90fb5a.
Report an issue: GitHub.