{"record":{"id":"62abc4da85d5ac43","repo":"parallax/jsPDF","slug":"methodname-is-only-available-in-advanced-api-m","errorCode":null,"errorMessage":"{methodName} is only available in 'advanced' API mode. You need to call advancedAPI() first.","messagePattern":"(.+?) is only available in 'advanced' API mode\\. You need to call advancedAPI\\(\\) first\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/jspdf.js","lineNumber":480,"sourceCode":"    if (doSwitch) {\n      advancedAPI.call(this);\n    }\n\n    return this;\n  };\n\n  /**\n   * @return {boolean} True iff the current API mode is \"advanced\". See {@link advancedAPI}.\n   * @memberof jsPDF#\n   * @name isAdvancedAPI\n   */\n  API.isAdvancedAPI = function() {\n    return apiMode === ApiMode.ADVANCED;\n  };\n\n  var advancedApiModeTrap = function(methodName) {\n    if (apiMode !== ApiMode.ADVANCED) {\n      throw new Error(\n        methodName +\n          \" is only available in 'advanced' API mode. \" +\n          \"You need to call advancedAPI() first.\"\n      );\n    }\n  };\n\n  var roundToPrecision = (API.roundToPrecision = API.__private__.roundToPrecision = function(\n    number,\n    parmPrecision\n  ) {\n    var tmpPrecision = precision || parmPrecision;\n    if (isNaN(number) || isNaN(tmpPrecision)) {\n      throw new Error(\"Invalid argument passed to jsPDF.roundToPrecision\");\n    }\n    return number.toFixed(tmpPrecision).replace(/0+$/, \"\");\n  });\n","sourceCodeStart":462,"sourceCodeEnd":498,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/jspdf.js#L462-L498","documentation":"Several graphics APIs only function when jsPDF is in 'advanced' API mode, which allows arbitrary transforms and pattern fills. The trap `advancedApiModeTrap` (src/jspdf.js:478) checks `apiMode !== ApiMode.ADVANCED` and throws for `addShadingPattern`, `beginTilingPattern`, `endTilingPattern`, and a `text()` call using a Matrix transform (src/jspdf.js:3547). The default mode is 'compat'; you must enter advanced mode via `doc.advancedAPI()` (src/jspdf.js:420) before calling these methods.","triggerScenarios":"Calling `doc.addShadingPattern(...)` or `doc.beginTilingPattern(...)` without first calling `doc.advancedAPI()`; calling `doc.text(...)` with a `transform` argument that is a Matrix while still in compat mode; using a plugin/helper that internally calls these methods without documenting the mode requirement.","commonSituations":"Copying an advanced example into a compat-mode document; a plugin that expects advanced mode but the host app never switches; forgetting that `advancedAPI(callback)` auto-switches back to compat after the callback — calling an advanced method after the callback returns fails.","solutions":["Wrap the advanced calls in `doc.advancedAPI(function(d){ ... })` so the mode is set and restored automatically.","Or manually `doc.advancedAPI()` (no callback) before the calls and `doc.compatAPI()` when done — note saveGraphicsState/restoreGraphicsState and form/tiling-pattern blocks must be balanced.","If using `text()` with a Matrix transform, ensure you are inside an advancedAPI block.","Check `doc.isAdvancedAPI()` returns true before invoking the guarded method as a runtime guard."],"exampleFix":"// before\n doc.addShadingPattern('diag', pattern);   // throws in compat mode\n\n// after\n doc.advancedAPI(function (d) {\n   d.addShadingPattern('diag', pattern);\n });","handlingStrategy":"validation","validationCode":"function runAdvanced(doc, fn) {\n  if (typeof doc.advancedAPI !== 'function') throw new Error('advancedAPI unavailable');\n  doc.advancedAPI(function (d) { fn(d); });\n}\n// usage:\nrunAdvanced(doc, function (d) { d.addShadingPattern('p', pat); });","typeGuard":"function isAdvancedReady(doc) {\n  return typeof doc.isAdvancedAPI === 'function' && doc.isAdvancedAPI();\n}","tryCatchPattern":"try {\n  doc.addShadingPattern(key, pat);\n} catch (e) {\n  if (/only available in 'advanced' API mode/.test(e.message)) {\n    doc.advancedAPI(function (d) { d.addShadingPattern(key, pat); });\n  } else throw e;\n}","preventionTips":["Always wrap advanced-only calls inside doc.advancedAPI(function(d){...}).","Remember advancedAPI(callback) reverts to compat after the callback — don't call advanced methods afterward.","Check doc.isAdvancedAPI() before guarded calls when mode is uncertain."],"tags":["apimode","advanced","patterns","transform","setfont"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}