{"record":{"id":"2229d1da8fafb8ca","repo":"parallax/jsPDF","slug":"invalid-format-format","errorCode":null,"errorMessage":"Invalid format: ${format}","messagePattern":"Invalid format: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/modules/html.js","lineNumber":966,"sourceCode":"      case \"ex\":\n        k = 6;\n        break;\n      default:\n        throw \"Invalid unit: \" + unit;\n    }\n    var pageHeight = 0;\n    var pageWidth = 0;\n\n    // Dimensions are stored as user units and converted to points on output\n    if (pageFormats.hasOwnProperty(format_as_string)) {\n      pageHeight = pageFormats[format_as_string][1] / k;\n      pageWidth = pageFormats[format_as_string][0] / k;\n    } else {\n      try {\n        pageHeight = format[1];\n        pageWidth = format[0];\n      } catch (err) {\n        throw new Error(\"Invalid format: \" + format);\n      }\n    }\n\n    var tmp;\n    // Handle page orientation\n    if (orientation === \"p\" || orientation === \"portrait\") {\n      orientation = \"p\";\n      if (pageWidth > pageHeight) {\n        tmp = pageWidth;\n        pageWidth = pageHeight;\n        pageHeight = tmp;\n      }\n    } else if (orientation === \"l\" || orientation === \"landscape\") {\n      orientation = \"l\";\n      if (pageHeight > pageWidth) {\n        tmp = pageWidth;\n        pageWidth = pageHeight;\n        pageHeight = tmp;","sourceCodeStart":948,"sourceCodeEnd":984,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/modules/html.js#L948-L984","documentation":"In html.js's page-format resolver, if the format is not a known named page size (a4, letter, etc.), the code tries to index it as an array (format[1], format[0]). If format is not array-like (a number, null, undefined, or an object without numeric indices), indexing throws and the catch block re-throws 'Invalid format: <format>'. The error is only reached for non-named, non-array formats.","triggerScenarios":"Calling the html() page setup (or jsPDF constructor routed through html.js) with format set to a number, a single number string, null, undefined, an empty array, or a bare object; passing a dimension array in the wrong order/shape; passing a custom format that is not [w, h].","commonSituations":"Typo'd page-size names ('A4' vs 'a4' — the table is lowercase); passing pixels as a bare number instead of ['595','842']; migrating from a config that used a different shape.","solutions":["Use a known lowercase named size: 'a4', 'letter', 'legal', etc.","Pass a two-element numeric array [width, height] in the current unit for custom sizes.","Verify the format value type before calling (string name OR [number, number]).","Watch case: the pageFormats keys are lowercase."],"exampleFix":"// before\nconst doc = new jsPDF({ format: 'A4' }); // 'A4' not in lowercase table -> throws [117]\n\n// after\nconst doc = new jsPDF({ format: 'a4' });\n// or custom:\nconst doc = new jsPDF({ format: [210, 297], unit: 'mm' });","handlingStrategy":"validation","validationCode":"const KNOWN_FORMATS = new Set(['a0','a1','a2','a3','a4','a5','a6','a7','a8','a9','a10','b0','b1','b2','b3','b4','b5','b6','b7','b8','b9','b10','c0','c1','c2','c3','c4','c5','c6','c7','c8','c9','c10','dl','letter','government-letter','legal','junior-legal','ledger','tabloid','credit-card']);\nfunction validFormat(f) {\n  if (typeof f === 'string') return KNOWN_FORMATS.has(f.toLowerCase());\n  if (Array.isArray(f) && f.length === 2 && f.every(Number.isFinite)) return true;\n  return false;\n}","typeGuard":"function isPageFormat(f) {\n  return (typeof f === 'string') || (Array.isArray(f) && f.length === 2 && f.every(v => typeof v === 'number' && Number.isFinite(v)));\n}","tryCatchPattern":"try {\n  const doc = new jsPDF({ format });\n} catch (e) {\n  if (/Invalid format/.test(e.message)) {\n    // fall back to a known size or a [w,h] array\n    const doc = new jsPDF({ format: 'a4' });\n  } else throw e;\n}","preventionTips":["Use lowercase named sizes (a4, letter) — the lookup table is lowercase.","For custom sizes pass [width, height] in the chosen unit.","Validate config-sourced format values at app startup."],"tags":["pdf","page-format","html","validation","config"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}