parallax/jsPDF · error · Error

Invalid argument passed to jsPDF.getDocumentProperty

Error message

Invalid argument passed to jsPDF.getDocumentProperty

What it means

`getDocumentProperty` (src/jspdf.js:1007) reads one of the five built-in metadata fields: `title`, `subject`, `author`, `keywords`, `creator`. It throws at src/jspdf.js:1012 if the requested key isn't in that set — jsPDF only models those standard Info-dictionary properties, not arbitrary custom keys.

Source

Thrown at src/jspdf.js:1013

    pmode
  ) {
    setZoomMode(zoom);
    setLayoutMode(layout);
    setPageMode(pmode);
    return this;
  };

  var documentProperties = {
    title: "",
    subject: "",
    author: "",
    keywords: "",
    creator: ""
  };

  API.__private__.getDocumentProperty = function(key) {
    if (Object.keys(documentProperties).indexOf(key) === -1) {
      throw new Error("Invalid argument passed to jsPDF.getDocumentProperty");
    }
    return documentProperties[key];
  };

  API.__private__.getDocumentProperties = function() {
    return documentProperties;
  };

  /**
   * Adds a properties to the PDF document.
   *
   * @param {Object} A property_name-to-property_value object structure.
   * @function
   * @instance
   * @returns {jsPDF}
   * @memberof jsPDF#
   * @name setDocumentProperties
   */

View on GitHub (pinned to a3930ce03a)

Solutions

  1. Use only the five allowed keys: title, subject, author, keywords, creator.
  2. For dates use `doc.getCreationDate()`; for the file id use `doc.internal.getFileId()`.
  3. If you need custom metadata, note jsPDF doesn't store arbitrary keys — extend via a plugin or store outside the Info dict.

Example fix

// before
 doc.internal.__private__.getDocumentProperty('producer');  // throws

// after
 // 'producer' isn't user-settable via this API; use a stored key:
 doc.internal.__private__.getDocumentProperty('creator');
Defensive patterns

Strategy: validation

Validate before calling

var PROP_KEYS = ['title','subject','author','keywords','creator'];
function getProp(doc, key) {
  if (PROP_KEYS.indexOf(key) === -1) return undefined;
  return doc.internal.__private__.getDocumentProperty(key);
}

Type guard

function isDocumentPropertyKey(k) {
  return ['title','subject','author','keywords','creator'].indexOf(k) !== -1;
}

Try / catch

try {
  val = doc.internal.__private__.getDocumentProperty(key);
} catch (e) {
  if (/getDocumentProperty/.test(e.message)) {
    val = undefined;  // unknown key -> no value
  } else throw e;
}

Prevention

When it happens

Trigger: `doc.internal.__private__.getDocumentProperty('producer')` (not a stored key); `'creationDate'` (handled separately via getCreationDate); `'custom_field'`; a typo like `'tittle'`.

Common situations: Treating getDocumentProperty as a generic key-value store; confusing it with getCreationDate/getFileId which are separate APIs; typos in property names from dynamic access.

Related errors


AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13). Data as JSON: /api/errors/c2f6a321df7d3b6b. Report an issue: GitHub.