parallax/jsPDF · error · Error
Invalid arguments passed to jsPDF.rect
Error message
Invalid arguments passed to jsPDF.rect
What it means
Thrown by jsPDF.rect when x, y, w, or h is NaN or the style is invalid. All four must be finite numbers; style must pass isValidStyle (undefined, null, 'S', 'D', 'F', 'DF', 'FD', 'f', 'f*', 'B', 'B*', 'n').
Source
Thrown at src/jspdf.js:4705
* @param {number} w Width (in units declared at inception of PDF document)
* @param {number} h Height (in units declared at inception of PDF document)
* @param {string=} style A string specifying the painting style or null. Valid styles include:
* 'S' [default] - stroke,
* 'F' - fill,
* and 'DF' (or 'FD') - fill then stroke.
* In "compat" API mode, a null value postpones setting the style so that a shape may be composed using multiple
* method calls. The last drawing method call used to define the shape should not have a null style argument.
*
* In "advanced" API mode this parameter is deprecated.
* @function
* @instance
* @returns {jsPDF}
* @memberof jsPDF#
* @name rect
*/
API.__private__.rect = API.rect = function(x, y, w, h, style) {
if (isNaN(x) || isNaN(y) || isNaN(w) || isNaN(h) || !isValidStyle(style)) {
throw new Error("Invalid arguments passed to jsPDF.rect");
}
if (apiMode === ApiMode.COMPAT) {
h = -h;
}
out(
[
hpf(scale(x)),
hpf(transformScaleY(y)),
hpf(scale(w)),
hpf(scale(h)),
"re"
].join(" ")
);
putStyle(style);
return this;
};View on GitHub (pinned to a3930ce03a)
Solutions
- Provide finite numeric x, y, w, h.
- Use a supported style code ('S', 'F', 'DF'/'FD') or null/undefined.
- Coerce or default any possibly-missing dimension before calling.
Example fix
// before pdf.rect(10, 10, 80, box.h, 'fill'); // box.h undefined -> NaN, 'fill' invalid // after pdf.rect(10, 10, 80, Number(box.h) || 0, 'F');
Defensive patterns
Strategy: validation
Validate before calling
const VALID_STYLES = [undefined, null, 'S','D','F','DF','FD','f','f*','B','B*','n'];
function safeRect(doc, x, y, w, h, style) {
if (![x,y,w,h].every(Number.isFinite)) throw new Error('x,y,w,h must be finite');
return doc.rect(x, y, w, h, VALID_STYLES.includes(style) ? style : 'S');
} Type guard
function isValidStyle(s) { return [undefined,null,'S','D','F','DF','FD','f','f*','B','B*','n'].includes(s); } Prevention
- Ensure all four dimensions are finite numbers.
- Use 'S'/'F'/'DF' instead of 'stroke'/'fill'.
- Default missing dimensions to 0 explicitly.
When it happens
Trigger: Calling rect() with an undefined dimension (e.g. missing height), a non-numeric width, or an unsupported style like 'stroke', 'fill', 'X', or a number.
Common situations: Human-readable style strings instead of PDF operator codes; dimensions computed from missing data; passing width/height swapped with non-numeric values; typos in style.
Related errors
- Invalid arguments passed to jsPDF.line
- Invalid arguments passed to jsPDF.lines
- Invalid arguments passed to jsPDF.triangle
- Invalid arguments passed to jsPDF.roundedRect
- Invalid arguments passed to jsPDF.ellipse
AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13).
Data as JSON: /api/errors/06e1bbce3654dcb6.
Report an issue: GitHub.