parallax/jsPDF · error · Error
Invalid arguments passed to jsPDF.context2d.transform
Error message
Invalid arguments passed to jsPDF.context2d.transform
What it means
transform validates all six matrix components (a,b,c,d,e,f) with isNaN before constructing and multiplying the matrix. Any undefined/missing/non-numeric component throws. This mirrors the HTML5 CanvasTransform.transform signature.
Source
Thrown at src/modules/context2d.js:1508
};
/**
* Replaces the current transformation matrix for the drawing
*
* @name transform
* @function
* @param a {Number} Horizontal scaling
* @param b {Number} Horizontal skewing
* @param c {Number} Vertical skewing
* @param d {Number} Vertical scaling
* @param e {Number} Horizontal moving
* @param f {Number} Vertical moving
* @description Each object on the canvas has a current transformation matrix.<br /><br />The transform() method replaces the current transformation matrix. It multiplies the current transformation matrix with the matrix described by:<br /><br /><br /><br />a c e<br /><br />b d f<br /><br />0 0 1<br /><br />In other words, the transform() method lets you scale, rotate, move, and skew the current context.
*/
Context2D.prototype.transform = function(a, b, c, d, e, f) {
if (isNaN(a) || isNaN(b) || isNaN(c) || isNaN(d) || isNaN(e) || isNaN(f)) {
console.error("jsPDF.context2d.transform: Invalid arguments", arguments);
throw new Error("Invalid arguments passed to jsPDF.context2d.transform");
}
var matrix = new Matrix(a, b, c, d, e, f);
this.ctx.transform = this.ctx.transform.multiply(matrix);
};
/**
* Resets the current transform to the identity matrix. Then runs transform()
*
* @name setTransform
* @function
* @param a {Number} Horizontal scaling
* @param b {Number} Horizontal skewing
* @param c {Number} Vertical skewing
* @param d {Number} Vertical scaling
* @param e {Number} Horizontal moving
* @param f {Number} Vertical moving
* @description Each object on the canvas has a current transformation matrix. <br /><br />The setTransform() method resets the current transform to the identity matrix, and then runs transform() with the same arguments.<br /><br />In other words, the setTransform() method lets you scale, rotate, move, and skew the current context.
*/View on GitHub (pinned to a3930ce03a)
Solutions
- Always pass six finite numbers; default missing components to the identity (1,0,0,1,0,0).
- If you have a Matrix, extract its fields (a,b,c,d,e,f) explicitly rather than passing the object.
- Validate all six with Number.isFinite before calling.
Example fix
// before ctx.transform(...matrixArray); // short array -> throws [112] // after const [a=1,b=0,c=0,d=1,e=0,f=0] = matrixArray.map(Number); if ([a,b,c,d,e,f].every(Number.isFinite)) ctx.transform(a,b,c,d,e,f);
Defensive patterns
Strategy: validation
Validate before calling
function safeTransform(ctx, a, b, c, d, e, f) {
// default to identity for missing components
const m = [a ?? 1, b ?? 0, c ?? 0, d ?? 1, e ?? 0, f ?? 0].map(Number);
if (!m.every(Number.isFinite)) return;
ctx.transform(...m);
} Type guard
function isTransformArgs(a,b,c,d,e,f) {
return [a,b,c,d,e,f].every(v => typeof v === 'number' && Number.isFinite(v));
} Try / catch
try { ctx.transform(a, b, c, d, e, f); }
catch (e2) { if (!/context2d.transform/.test(e2.message)) throw e2; } Prevention
- Always pass six scalar components, never a Matrix object.
- When spreading an array, ensure length === 6.
- Default missing components to identity values (1,0,0,1,0,0).
When it happens
Trigger: ctx.transform(a,b,c,d,e,f) with fewer than six finite numeric arguments; passing a Matrix object instead of its six components; reading components from a partially-initialized matrix.
Common situations: Confusing setTransform/transform (which take six scalars) with applying a Matrix object; spreading a short array into the call; defaulting missing components incorrectly.
Related errors
- Invalid arguments passed to jsPDF.context2d.scale
- Invalid arguments passed to jsPDF.context2d.rotate
- Invalid arguments passed to jsPDF.context2d.translate
- Invalid arguments passed to jsPDF.context2d.rect
- Invalid arguments passed to jsPDF.context2d.fillRect
AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13).
Data as JSON: /api/errors/c8be8c516ba17ed8.
Report an issue: GitHub.