parallax/jsPDF · error · Error
Invalid arguments passed to jsPDF.line
Error message
Invalid arguments passed to jsPDF.line
What it means
Thrown by jsPDF.line when any coordinate is NaN or the style is not a valid painting style. Coordinates x1, y1, x2, y2 must all be finite numbers, and style must pass isValidStyle. Valid styles are: undefined, null, 'S', 'D', 'F', 'DF', 'FD', 'f', 'f*', 'B', 'B*', 'n'.
Source
Thrown at src/jspdf.js:4530
* @function
* @instance
* @param {number} x1
* @param {number} y1
* @param {number} x2
* @param {number} y2
* @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. 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. default: 'S'
* @returns {jsPDF}
* @memberof jsPDF#
*/
API.__private__.line = API.line = function(x1, y1, x2, y2, style) {
if (
isNaN(x1) ||
isNaN(y1) ||
isNaN(x2) ||
isNaN(y2) ||
!isValidStyle(style)
) {
throw new Error("Invalid arguments passed to jsPDF.line");
}
if (apiMode === ApiMode.COMPAT) {
return this.lines([[x2 - x1, y2 - y1]], x1, y1, [1, 1], style || "S");
} else {
return this.lines([[x2 - x1, y2 - y1]], x1, y1, [1, 1]).stroke();
}
};
/**
* @typedef {Object} PatternData
* {Matrix|undefined} matrix
* {Number|undefined} xStep
* {Number|undefined} yStep
* {Array.<Number>|undefined} boundingBox
*/
/**
* Adds series of curves (straight lines or cubic bezier curves) to canvas, starting at `x`, `y` coordinates.View on GitHub (pinned to a3930ce03a)
Solutions
- Use a supported style code ('S' to stroke, 'F' to fill, 'DF'/'FD' for both) or null/undefined.
- Ensure all four coordinates are finite numbers.
- Map friendly style names to the PDF operator codes in your wrapper.
Example fix
// before pdf.line(10, 10, 100, 50, 'stroke'); // invalid style // after pdf.line(10, 10, 100, 50, 'S'); // stroke
Defensive patterns
Strategy: validation
Validate before calling
const VALID_STYLES = [undefined, null, 'S','D','F','DF','FD','f','f*','B','B*','n'];
function safeLine(doc, x1, y1, x2, y2, style) {
if (![x1,y1,x2,y2].every(Number.isFinite)) throw new Error('coordinates must be finite');
return doc.line(x1, y1, x2, y2, 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
- Use PDF operator codes ('S','F','DF') not friendly names.
- Validate coordinates with Number.isFinite.
- Centralize a style whitelist in a shared helper.
When it happens
Trigger: Calling line() with a missing/undefined coordinate, a non-numeric coordinate, or a style string like 'X', 'stroke', 'fill', or a number such as 1.
Common situations: Passing a human-readable style ('stroke'/'fill') instead of the PDF operators; coordinates derived from missing properties; typos in the style code; numbers used as style.
Related errors
- Invalid arguments passed to jsPDF.lines
- Invalid arguments passed to jsPDF.rect
- 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/7a9de32b5187df91.
Report an issue: GitHub.