parallax/jsPDF · error · Error

ObjectId must be passed to putStream for file encryption

Error message

ObjectId must be passed to putStream for file encryption

What it means

`putStream` (src/jspdf.js:1761) writes a PDF stream object and, when encryption is enabled (`options.encryption` passed to the constructor, see src/jspdf.js:228), it must encrypt the stream — which requires the stream's object id. The guard at src/jspdf.js:1772 throws if `encryptionOptions !== null` but `options.objectId` is undefined. This is normally an internal invariant: every stream-writing call site supplies an objectId. A user hits it when a plugin or custom output hook calls `doc.internal.__private__.putStream({ data })` directly without an objectId on an encrypted document.

Source

Thrown at src/jspdf.js:1773

  });

  var getFilters = (API.__private__.getFilters = function() {
    return filters;
  });

  var putStream = (API.__private__.putStream = function(options) {
    options = options || {};
    var data = options.data || "";
    var filters = options.filters || getFilters();
    var alreadyAppliedFilters = options.alreadyAppliedFilters || [];
    var addLength1 = options.addLength1 || false;
    var valueOfLength1 = data.length;
    var objectId = options.objectId;
    var encryptor = function(data) {
      return data;
    };
    if (encryptionOptions !== null && typeof objectId == "undefined") {
      throw new Error(
        "ObjectId must be passed to putStream for file encryption"
      );
    }
    if (encryptionOptions !== null) {
      encryptor = encryption.encryptor(objectId, 0);
    }

    var processedData = {};
    if (filters === true) {
      filters = ["FlateEncode"];
    }
    var keyValues = options.additionalKeyValues || [];
    if (typeof jsPDF.API.processDataByFilters !== "undefined") {
      processedData = jsPDF.API.processDataByFilters(data, filters);
    } else {
      processedData = { data: data, reverseChain: [] };
    }
    var filterAsString =

View on GitHub (pinned to a3930ce03a)

Solutions

  1. If calling putStream directly on an encrypted doc, always pass `options.objectId` (a valid allocated object number).
  2. Update third-party plugins to versions that support encryption (they must thread objectId into putStream).
  3. If you don't actually need encryption, remove the `encryption` option from the constructor.
  4. Allocate an object id via the internal API (`doc.internal.newObject`) and pass it through.

Example fix

// before (encrypted doc, plugin omits id)
 doc.internal.__private__.putStream({ data: streamBytes });  // throws

// after
 var objId = doc.internal.newObject();
 doc.internal.__private__.putStream({ data: streamBytes, objectId: objId });
Defensive patterns

Strategy: validation

Validate before calling

function putStreamSafe(doc, opts) {
  var enc = doc.internal.__private__.encryptor;
  if (enc && (opts.objectId == null)) {
    opts.objectId = doc.internal.newObject(); // allocate before writing
  }
  return doc.internal.__private__.putStream(opts);
}

Type guard

function hasObjectIdForEncryption(doc, opts) {
  // encryption is active when doc.internal.security exists
  return !(doc.internal.security && (opts.objectId == null));
}

Try / catch

try {
  doc.internal.__private__.putStream({ data: bytes });
} catch (e) {
  if (/ObjectId must be passed/.test(e.message)) {
    var id = doc.internal.newObject();
    doc.internal.__private__.putStream({ data: bytes, objectId: id });
  } else throw e;
}

Prevention

When it happens

Trigger: Creating `new jsPDF({ encryption: {...} })` and then a plugin/form-integration calls `putStream` without `objectId`; monkey-patching the output pipeline and dropping the objectId; acroform or annotation code paths that don't thread objectId through on encrypted docs.

Common situations: Third-party plugins that weren't written with encryption in mind; custom stream injection during output; bugs in plugin versions that predate encryption support.

Related errors


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