mozilla/pdf.js · error · Error
Invalid pages rotation angle.
Error message
Invalid pages rotation angle.
What it means
Thrown by PDFViewer.pagesRotation setter when rotation fails isValidRotation (must be an integer multiple of 90). Rotation is applied to all page views and must be a valid cardinal angle.
Source
Thrown at web/pdf_viewer.js:646
if (!this.pdfDocument) {
return;
}
this.#setScale(val, { noScroll: false });
}
/**
* @type {number}
*/
get pagesRotation() {
return this._pagesRotation;
}
/**
* @param {number} rotation - The rotation of the pages (0, 90, 180, 270).
*/
set pagesRotation(rotation) {
if (!isValidRotation(rotation)) {
throw new Error("Invalid pages rotation angle.");
}
if (!this.pdfDocument) {
return;
}
// Normalize the rotation, by clamping it to the [0, 360) range.
rotation %= 360;
if (rotation < 0) {
rotation += 360;
}
if (this._pagesRotation === rotation) {
return; // The rotation didn't change.
}
this.clearSelection();
this._pagesRotation = rotation;
const pageNumber = this._currentPageNumber;
this.refresh(true, { rotation });View on GitHub (pinned to 5903d58d58)
Solutions
- Pass only integer multiples of 90: 0, 90, 180, 270.
- Snap input: rotation = Math.round(rotation / 90) * 90.
- Guard with isValidRotation before assigning.
Example fix
// before
viewer.pagesRotation = degrees;
// after
if (Number.isInteger(degrees) && degrees % 90 === 0) {
viewer.pagesRotation = ((degrees % 360) + 360) % 360;
} Defensive patterns
Strategy: validation
Validate before calling
if (Number.isInteger(rotation) && rotation % 90 === 0) {
viewer.pagesRotation = ((rotation % 360) + 360) % 360;
} Type guard
function isValidRotation(angle) {
return Number.isInteger(angle) && angle % 90 === 0;
} Prevention
- Snap rotation to multiples of 90.
- Use the shared isValidRotation helper.
- Normalize rotation on deserialization.
When it happens
Trigger: Setting viewer.pagesRotation = 45, 90.5, NaN, or a non-number. Derived from a rotation control passing arbitrary degrees or untrusted state.
Common situations: Custom rotation buttons not snapping to 90-degree steps; deserialized rotation that drifted; float arithmetic producing 179.999.
Related errors
- Invalid thumbnails rotation angle.
- Invalid page number.
- Invalid numeric scale.
- Invalid optionalContentConfigPromise: ${promise}
- Invalid scroll mode: ${mode}
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/23f8e28beb2a06d4.
Report an issue: GitHub.