{"record":{"id":"5f1ab2233ff57c77","repo":"mozilla/pdf.js","slug":"encoding-is-not-a-name-nor-a-dict","errorCode":null,"errorMessage":"Encoding is not a Name nor a Dict","messagePattern":"Encoding is not a Name nor a Dict","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"warning","filePath":"src/core/evaluator.js","lineNumber":3677,"sourceCode":"            const data = xref.fetchIfRef(entry);\n            if (typeof data === \"number\") {\n              index = data;\n            } else if (data instanceof Name) {\n              differences[index++] = data.name;\n            } else {\n              throw new FormatError(\n                `Invalid entry in 'Differences' array: ${data}`\n              );\n            }\n          }\n        }\n      } else if (encoding instanceof Name) {\n        baseEncodingName = encoding.name;\n      } else {\n        const msg = \"Encoding is not a Name nor a Dict\";\n\n        if (!this.options.ignoreErrors) {\n          throw new FormatError(msg);\n        }\n        warn(msg);\n      }\n      // According to table 114 if the encoding is a named encoding it must be\n      // one of these predefined encodings.\n      if (\n        baseEncodingName !== \"MacRomanEncoding\" &&\n        baseEncodingName !== \"MacExpertEncoding\" &&\n        baseEncodingName !== \"WinAnsiEncoding\"\n      ) {\n        baseEncodingName = null;\n      }\n    }\n\n    const nonEmbeddedFont = !properties.file || properties.isInternalFont,\n      isSymbolsFontName = getSymbolsFonts()[properties.name];\n    // Ignore an incorrectly specified named encoding for non-embedded\n    // symbol fonts (fixes issue16464.pdf).","sourceCodeStart":3659,"sourceCodeEnd":3695,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/evaluator.js#L3659-L3695","documentation":"Thrown when a font's /Encoding entry is neither a Name (e.g. /WinAnsiEncoding) nor a Dictionary (containing /BaseEncoding and /Differences). Per the PDF spec, /Encoding must be one of those two forms. Unlike most guards here, this one is gated by options.ignoreErrors — if stopAtErrors is false it degrades to a warning and falls back to a default encoding.","triggerScenarios":"A font dictionary whose /Encoding is a string, number, array, null, or any non-Name non-Dict object. Fires in PartialEvaluator.translateFont during page/font load. With ignoreErrors=true (the default render path) it logs a warning and continues; with stopAtErrors=true it propagates as an exception.","commonSituations":"Corrupt or non-conformant PDFs from buggy generators. Also appears after partial PDF repair tools that stripped the encoding object. Frequently seen alongside other font errors in scraped/faxed documents.","solutions":["Set stopAtErrors: false (or omit it) so this specific check degrades to a warn() and uses a fallback encoding, allowing the rest of the document to render.","Repair the PDF with qpdf or Ghostscript to rebuild the Encoding entry.","If authoring, ensure each font /Encoding is either a predefined Name or a proper encoding Dictionary.","Filter such PDFs upstream if text fidelity is required, since fallback encodings will mis-map glyphs."],"exampleFix":"// before\ngetDocument({ url, stopAtErrors: true }); // throws on bad Encoding\n\n// after\ngetDocument({ url }); // ignoreErrors defaults true -> warn + fallback encoding","handlingStrategy":"validation","validationCode":"// This guard is already gated by options.ignoreErrors in PDF.js itself.\n// To benefit from the degrade-to-warning path, do NOT set stopAtErrors:\nconst pdf = await getDocument({ url /*, stopAtErrors: false is default */ }).promise;\n// The font will load with a fallback encoding; only a console.warn is emitted.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Leave stopAtErrors at its default (false) so this specific check warns rather than throws.","Repair /Encoding entries with Ghostscript or qpdf before processing if text fidelity matters.","If you must use stopAtErrors: true, catch FormatError per page and skip."],"tags":["pdf","font","encoding","format-error","ignore-errors"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}