{"record":{"id":"40c6abfbb04a045b","repo":"parallax/jsPDF","slug":"invalid-arguments-passed-to-jspdf-setdocumentprope","errorCode":null,"errorMessage":"Invalid arguments passed to jsPDF.setDocumentProperty","messagePattern":"Invalid arguments passed to jsPDF\\.setDocumentProperty","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/jspdf.js","lineNumber":1046,"sourceCode":"   * @returns {jsPDF}\n   * @memberof jsPDF#\n   * @name setDocumentProperties\n   */\n  API.__private__.setDocumentProperties = API.setProperties = API.setDocumentProperties = function(\n    properties\n  ) {\n    // copying only those properties we can render.\n    for (var property in documentProperties) {\n      if (documentProperties.hasOwnProperty(property) && properties[property]) {\n        documentProperties[property] = properties[property];\n      }\n    }\n    return this;\n  };\n\n  API.__private__.setDocumentProperty = function(key, value) {\n    if (Object.keys(documentProperties).indexOf(key) === -1) {\n      throw new Error(\"Invalid arguments passed to jsPDF.setDocumentProperty\");\n    }\n    return (documentProperties[key] = value);\n  };\n\n  var fonts = {}; // collection of font objects, where key is fontKey - a dynamically created label for a given font.\n  var fontmap = {}; // mapping structure fontName > fontStyle > font key - performance layer. See addFont()\n  var activeFontKey; // will be string representing the KEY of the font as combination of fontName + fontStyle\n  var fontStateStack = []; //\n  var patterns = {}; // collection of pattern objects\n  var patternMap = {}; // see fonts\n  var gStates = {}; // collection of graphic state objects\n  var gStatesMap = {}; // see fonts\n  var activeGState = null;\n  var scaleFactor; // Scale factor\n  var page = 0;\n  var pagesContext = [];\n  var events = new PubSub(API);\n  var hotfixes = options.hotfixes || [];","sourceCodeStart":1028,"sourceCodeEnd":1064,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/jspdf.js#L1028-L1064","documentation":"`setDocumentProperty` (src/jspdf.js:1044) writes one of the same five metadata keys (title, subject, author, keywords, creator). It throws at src/jspdf.js:1045 when the key is not in `documentProperties`. Note the public `setProperties`/`setDocumentProperties` (src/jspdf.js:1032) is tolerant — it silently ignores unknown keys — but the single-property setter is strict.","triggerScenarios":"`doc.internal.__private__.setDocumentProperty('producer', 'me')`; `'CreationDate'`; a dynamic key from user input that isn't one of the five; `'tittle'` typo.","commonSituations":"Looping over an arbitrary object and calling setDocumentProperty for each key (use setProperties instead, which ignores unknown keys); case mismatch (`'Title'` vs `'title'`); expecting custom fields to be storable.","solutions":["Restrict keys to title, subject, author, keywords, creator (lowercase).","For bulk sets from an arbitrary object, use `doc.setProperties(obj)` which safely ignores unknown keys.","Validate/normalize keys before calling the single-property setter."],"exampleFix":"// before\n doc.internal.__private__.setDocumentProperty('Title', 'Report');  // throws (case)\n\n// after\n doc.setProperties({ title: 'Report', author: 'me' });  // safe, ignores unknowns","handlingStrategy":"validation","validationCode":"var PROP_KEYS = ['title','subject','author','keywords','creator'];\nfunction setProp(doc, key, value) {\n  if (PROP_KEYS.indexOf(key) === -1) return doc; // ignore unknown\n  return doc.internal.__private__.setDocumentProperty(key, value);\n}\n// or simply use the tolerant bulk API:\ndoc.setProperties({ title: t, author: a });","typeGuard":"function isDocumentPropertyKey(k) {\n  return ['title','subject','author','keywords','creator'].indexOf(k) !== -1;\n}","tryCatchPattern":"try {\n  doc.internal.__private__.setDocumentProperty(key, value);\n} catch (e) {\n  if (/setDocumentProperty/.test(e.message)) {\n    // unknown key -> use tolerant bulk API instead\n    var o = {}; o[key] = value; doc.setProperties(o);\n  } else throw e;\n}","preventionTips":["Prefer doc.setProperties(obj) for bulk sets — it ignores unknown keys.","Normalize keys to lowercase before the single-property setter.","Don't loop arbitrary objects through setDocumentProperty."],"tags":["metadata","properties","validation"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}