mozilla/pdf.js · error · FormatError
Illegal character: ${ch}
Error message
Illegal character: ${ch} What it means
Error "Illegal character: ${ch}" thrown in mozilla/pdf.js.
Source
Thrown at src/core/parser.js:1354
ch = this.nextChar();
if (ch === 0x3e) {
this.nextChar();
return Cmd.get(">>");
}
return Cmd.get(">");
case 0x7b: // '{'
this.nextChar();
return Cmd.get("{");
case 0x7d: // '}'
this.nextChar();
return Cmd.get("}");
case 0x29: // ')'
// Consume the current character in order to avoid permanently hanging
// the worker thread if `Lexer.getObj` is called from within a loop
// containing try-catch statements, since we would otherwise attempt
// to parse the *same* character over and over (fixes issue8061.pdf).
this.nextChar();
throw new FormatError(`Illegal character: ${ch}`);
}
// Start reading a command.
let str = String.fromCharCode(ch);
// A valid command cannot start with a non-visible ASCII character,
// and the next character may be (the start of) a valid command.
if (ch < 0x20 || ch > 0x7f) {
const nextCh = this.peekChar();
if (nextCh >= 0x20 && nextCh <= 0x7f) {
this.nextChar();
return Cmd.get(str);
}
}
const knownCommands = this.knownCommands;
let knownCommandFound = knownCommands?.[str] !== undefined;
while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
// Stop if a known command is found and next character does not make
// the string a command.View on GitHub (pinned to 5903d58d58)
Solutions
- Remove the illegal character from the token being parsed; PDF lexical rules only allow regular characters outside delimiters and whitespace.
- If the file is corrupted or truncated, obtain a clean copy of the PDF.
When it happens
Trigger: Thrown at src/core/parser.js:1354 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/a96c77fa411172e0.
Report an issue: GitHub.