parallax/jsPDF · error · Error

Exception while creating AcroformDictionary

Error message

Exception while creating AcroformDictionary

What it means

Thrown by initializeAcroForm when it is asked to initialize the AcroForm plugin but scope.internal.acroformPlugin.acroFormDictionaryRoot already exists. This is a re-initialization guard: the dictionary root should be created exactly once. A second initialize attempt indicates duplicate init or corrupted plugin state.

Source

Thrown at src/modules/acroform.js:705

      }
      delete fieldArray[key];
    }
  }
};

var initializeAcroForm = function(scope, formObject) {
  formObject.scope = scope;
  if (
    scope.internal !== undefined &&
    (scope.internal.acroformPlugin === undefined ||
      scope.internal.acroformPlugin.isInitialized === false)
  ) {
    AcroFormField.FieldNum = 0;
    scope.internal.acroformPlugin = JSON.parse(
      JSON.stringify(acroformPluginTemplate)
    );
    if (scope.internal.acroformPlugin.acroFormDictionaryRoot) {
      throw new Error("Exception while creating AcroformDictionary");
    }
    scaleFactor = scope.internal.scaleFactor;
    // The Object Number of the AcroForm Dictionary
    scope.internal.acroformPlugin.acroFormDictionaryRoot = new AcroFormDictionary();
    scope.internal.acroformPlugin.acroFormDictionaryRoot.scope = scope;

    // add Callback for creating the AcroForm Dictionary
    scope.internal.acroformPlugin.acroFormDictionaryRoot._eventID = scope.internal.events.subscribe(
      "postPutResources",
      function() {
        AcroFormDictionaryCallback(scope);
      }
    );

    scope.internal.events.subscribe("buildDocument", function() {
      annotReferenceCallback(scope);
    }); // buildDocument

View on GitHub (pinned to a3930ce03a)

Solutions

  1. Initialize AcroForm once per document and reuse the existing plugin state.
  2. Check isInitialized / acroFormDictionaryRoot before triggering initialization.
  3. Use a fresh jsPDF instance for each generated form document.

Example fix

// before (two code paths both add fields -> double init)
buildFormA(doc); buildFormB(doc); // second init throws

// after
if (!doc.internal.acroformPlugin || !doc.internal.acroformPlugin.acroFormDictionaryRoot) {
  buildFormA(doc);
}
buildFormB(doc); // reuses existing plugin state
Defensive patterns

Strategy: try-catch

Validate before calling

function acroFormNotInitialized(doc) {
  var p = doc.internal && doc.internal.acroformPlugin;
  return !p || !p.isInitialized || !p.acroFormDictionaryRoot;
}
// only trigger form building when not yet initialized

Type guard

function isAcroFormInitialized(doc) {
  return !!(doc.internal && doc.internal.acroformPlugin &&
            doc.internal.acroformPlugin.acroFormDictionaryRoot);
}

Try / catch

try {
  initializeOrAddField(doc, field);
} catch (e) {
  if (/Exception while creating AcroformDictionary/.test(e.message)) {
    // already initialized; just add the field to existing plugin
    doc.addField(field);
  } else throw e;
}

Prevention

When it happens

Trigger: Adding AcroForm fields in a way that invokes initializeAcroForm twice (e.g. interleaving field creation with manual plugin manipulation), or a stale acroformPlugin object that retained a previous acroFormDictionaryRoot after a soft reset.

Common situations: Building forms across multiple code paths that both init forms; a jsPDF instance reused after an AcroForm build; a custom workflow that calls internal init directly.

Related errors


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