parallax/jsPDF · error · Error
Invalid arguments passed to jsPDF.setDocumentProperty
Error message
Invalid arguments passed to jsPDF.setDocumentProperty
What it means
`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.
Source
Thrown at src/jspdf.js:1046
* @returns {jsPDF}
* @memberof jsPDF#
* @name setDocumentProperties
*/
API.__private__.setDocumentProperties = API.setProperties = API.setDocumentProperties = function(
properties
) {
// copying only those properties we can render.
for (var property in documentProperties) {
if (documentProperties.hasOwnProperty(property) && properties[property]) {
documentProperties[property] = properties[property];
}
}
return this;
};
API.__private__.setDocumentProperty = function(key, value) {
if (Object.keys(documentProperties).indexOf(key) === -1) {
throw new Error("Invalid arguments passed to jsPDF.setDocumentProperty");
}
return (documentProperties[key] = value);
};
var fonts = {}; // collection of font objects, where key is fontKey - a dynamically created label for a given font.
var fontmap = {}; // mapping structure fontName > fontStyle > font key - performance layer. See addFont()
var activeFontKey; // will be string representing the KEY of the font as combination of fontName + fontStyle
var fontStateStack = []; //
var patterns = {}; // collection of pattern objects
var patternMap = {}; // see fonts
var gStates = {}; // collection of graphic state objects
var gStatesMap = {}; // see fonts
var activeGState = null;
var scaleFactor; // Scale factor
var page = 0;
var pagesContext = [];
var events = new PubSub(API);
var hotfixes = options.hotfixes || [];View on GitHub (pinned to a3930ce03a)
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.
Example fix
// before
doc.internal.__private__.setDocumentProperty('Title', 'Report'); // throws (case)
// after
doc.setProperties({ title: 'Report', author: 'me' }); // safe, ignores unknowns Defensive patterns
Strategy: validation
Validate before calling
var PROP_KEYS = ['title','subject','author','keywords','creator'];
function setProp(doc, key, value) {
if (PROP_KEYS.indexOf(key) === -1) return doc; // ignore unknown
return doc.internal.__private__.setDocumentProperty(key, value);
}
// or simply use the tolerant bulk API:
doc.setProperties({ title: t, author: a }); Type guard
function isDocumentPropertyKey(k) {
return ['title','subject','author','keywords','creator'].indexOf(k) !== -1;
} Try / catch
try {
doc.internal.__private__.setDocumentProperty(key, value);
} catch (e) {
if (/setDocumentProperty/.test(e.message)) {
// unknown key -> use tolerant bulk API instead
var o = {}; o[key] = value; doc.setProperties(o);
} else throw e;
} Prevention
- 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.
When it happens
Trigger: `doc.internal.__private__.setDocumentProperty('producer', 'me')`; `'CreationDate'`; a dynamic key from user input that isn't one of the five; `'tittle'` typo.
Common situations: 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.
Related errors
- Invalid argument passed to jsPDF.getDocumentProperty
- Invalid argument passed to jsPDF.setCreationDate
- Invalid arguments passed to PubSub.subscribe (jsPDF-module)
- Invalid Combination of fontweight and fontstyle
- zoom must be Integer (e.g. 2), a percentage Value (e.g. 300%
AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13).
Data as JSON: /api/errors/40c6abfbb04a045b.
Report an issue: GitHub.