{"record":{"id":"12a86a1c8a28a283","repo":"mozilla/pdf.js","slug":"fontfile-is-empty","errorCode":null,"errorMessage":"FontFile is empty","messagePattern":"FontFile is empty","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"warning","filePath":"src/core/evaluator.js","lineNumber":4629,"sourceCode":"        fontFile = descriptor.get(n);\n        if (fontFile) {\n          fontFileN = n;\n          break;\n        }\n      }\n\n      if (fontFile) {\n        if (!(fontFile instanceof BaseStream)) {\n          throw new FormatError(\"FontFile should be a stream\");\n        } else {\n          if (fontFile.isAsync) {\n            const bytes = await fontFile.asyncGetBytes();\n            if (bytes) {\n              fontFile = new Stream(bytes, 0, bytes.length, fontFile.dict);\n            }\n          }\n          if (fontFile.isEmpty) {\n            throw new FormatError(\"FontFile is empty\");\n          }\n        }\n      }\n    } catch (ex) {\n      if (!this.options.ignoreErrors) {\n        throw ex;\n      }\n      warn(`translateFont - fetching \"${fontName.name}\" font file: \"${ex}\".`);\n      fontFile = null;\n    }\n    let isInternalFont = false;\n    let glyphScaleFactors = null;\n    let systemFontInfo = null;\n    if (fontFile) {\n      if (fontFile.dict) {\n        const subtypeEntry = fontFile.dict.get(\"Subtype\");\n        if (subtypeEntry instanceof Name) {\n          subtype = subtypeEntry.name;","sourceCodeStart":4611,"sourceCodeEnd":4647,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/evaluator.js#L4611-L4647","documentation":"Thrown inside translateFont() when a font descriptor's embedded font stream exists and is a valid BaseStream but contains zero bytes (isEmpty is true). An empty font program cannot be parsed, so PDF.js refuses it. Like error 111, this is inside the ignoreErrors-aware try/catch, so the default render path warns and substitutes a fallback font rather than crashing.","triggerScenarios":"A /FontFile* stream whose /Length is 0 or whose bytes are exhausted, often because the stream data was truncated or never written despite the stream object existing. Fires during translateFont() after the stream-type check passes.","commonSituations":"Truncated downloads of PDFs (font stream is at the end and got cut off), faulty PDF optimizers that zeroed stream contents, or generators that wrote a stream header but failed to flush the buffer. Common in PDFs transferred over unstable connections or stored on flaky media.","solutions":["Re-download or re-acquire the PDF from its source to ensure completeness; verify file size matches expectation.","Re-embed the font from the source document via a conformant exporter.","Rely on ignoreErrors (default) to fall back to a standard font — text will render with substituted glyphs.","If authoring, write a unit test that asserts each embedded font stream has non-zero length before publishing the PDF."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Already gated by options.ignoreErrors. To avoid the throw, use default path:\nconst pdf = await getDocument({ url }).promise;\n// Empty font streams will warn and fall back to a standard font.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify PDF completeness (file size, MD5) before processing to rule out truncated font streams.","When authoring, assert each embedded font stream has non-zero length before publishing.","Leave stopAtErrors at default so empty streams warn and substitute a fallback font."],"tags":["pdf","font","font-file","empty-stream","format-error","ignore-errors"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}