mozilla/pdf.js · warning · FormatError

Unsupported CID string (charCode ${charCode}): "${cid}".

Error message

Unsupported CID string (charCode ${charCode}): "${cid}".

What it means

Thrown (or warned) by convertCidString() when a CMap iteration yields a CID as a string whose length is neither 1 nor 2 bytes. CIDs in PDF composite fonts are 8-bit or 16-bit values; a string of length 0 or >= 3 is not representable as a valid CID.

Source

Thrown at src/core/fonts.js:448

}

// Please refer to:
//  - https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6name.html
//  - https://learn.microsoft.com/en-us/typography/opentype/spec/name#windows-language-ids
function isWinNameRecord(r) {
  return r.platform === 3 && r.encoding === 1 && r.language === 0x409;
}

function convertCidString(charCode, cid, shouldThrow = false) {
  switch (cid.length) {
    case 1:
      return cid.charCodeAt(0);
    case 2:
      return (cid.charCodeAt(0) << 8) | cid.charCodeAt(1);
  }
  const msg = `Unsupported CID string (charCode ${charCode}): "${cid}".`;
  if (shouldThrow) {
    throw new FormatError(msg);
  }
  warn(msg);
  return cid;
}

/**
 * Rebuilds the char code to glyph ID map by moving all char codes to the
 * private use area. This is done to avoid issues with various problematic
 * unicode areas where either a glyph won't be drawn or is deformed by a
 * shaper.
 * @returns {Object} Two properties:
 * 'toFontChar' - maps original char codes(the value that will be read
 * from commands such as show text) to the char codes that will be used in the
 * font that we build
 * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
 */
function adjustMapping(charCodeToGlyphId, hasGlyph, newGlyphZeroId, toUnicode) {
  const newMap = Object.create(null);

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Verify the PDF's CMap resource matches the font's CIDSystemInfo (Registry, Ordering, Supplement).
  2. Rebuild the PDF with a compliant generator to ensure CMaps emit 1- or 2-byte CID strings.
  3. If the CMap is corrupt, replace it with the correct standard CMap (e.g., Identity-H, UniJIS-UCS2-H).
  4. Report the issue to the PDF producer; the CID string encoding is non-conformant.
Defensive patterns

Strategy: try-catch

Try / catch

// convertCidString with shouldThrow=true fires during font processing.
// At the display API level, font loading errors surface during render:
try {
  await page.render(renderParams).promise;
} catch (err) {
  if (err.message?.includes('Unsupported CID string')) {
    console.warn('CMap produced an invalid CID string; some glyphs may be unmapped.');
  } else { throw err; }
}

Prevention

When it happens

Trigger: convertCidString(charCode, cid, true) is called when shouldThrow=true during composite font charCodeToGlyphId mapping (fonts.js:3044), and cid.length is not 1 or 2. When shouldThrow is false (default), the same condition emits warn() instead.

Common situations: A corrupt or non-standard CMap file that emits CID strings with unexpected lengths. A CMap encoding mismatch where the CIDSystemInfo declares a different Registry/Supplement than the actual CMap data. PDFs from legacy systems with hand-crafted CMap resources. Character codes mapped through a broken ToUnicode or CIDToGIDMap.

Related errors


AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13). Data as JSON: /api/errors/fc036255a80f082c. Report an issue: GitHub.