mozilla/pdf.js · error · Error
Invalid rotation: must be a multiple of 90
Error message
Invalid rotation: must be a multiple of 90
What it means
Thrown by the setter of `Field.rotation` (src/scripting_api/field.js:212). A field's rotation must be a whole-number multiple of 90 degrees (0, 90, 180, 270) to align with the PDF coordinate system. The setter floors the value first, then rejects anything not divisible by 90.
Solutions
- Quantize the angle before assigning: `f.rotation = Math.round(angle / 90) * 90`.
- Ensure the source value is in degrees, not radians (`angle * 180 / Math.PI`).
- Floor explicitly and assert divisibility before the call to give a clearer error.
Example fix
// before f.rotation = degrees; // after f.rotation = Math.round(degrees / 90) * 90; // 0, 90, 180, 270
Defensive patterns
Strategy: validation
Validate before calling
function setRotationSafe(field, angle) {
const deg = Math.round(Number(angle) / 90) * 90;
if (!Number.isFinite(deg)) return false;
field.rotation = deg;
return true;
} Type guard
function isQuantized90(v) {
const n = Math.floor(Number(v));
return Number.isFinite(n) && n % 90 === 0;
} Prevention
- Quantize angles to 90-degree increments before assigning.
- Confirm the source unit is degrees, not radians.
- Floor and assert divisibility up front for a clearer error than the library's.
When it happens
Trigger: Assigning `f.rotation = 45`, `f.rotation = 12.5`, or a computed angle from `Math.atan2(...)` that is not quantized to 90. Passing a value in radians by mistake.
Common situations: Scripts that rotate a field to match a diagonal line or an image angle; reading a rotation out of an annotation whose value was never quantized; off-by-one on a UI slider that snaps to 1-degree steps.
Related errors
- field.numItems is read-only
- field.page is read-only
- Invalid argument value
- Invalid number of params in printf
- Not a choice widget
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/4b455c3e861618a5.
Report an issue: GitHub.
Appendix: source
Thrown at src/scripting_api/field.js:212
this.strokeColor = color;
}
get page() {
return this._page;
}
set page(_) {
throw new Error("field.page is read-only");
}
get rotation() {
return this._rotation;
}
set rotation(angle) {
angle = Math.floor(angle);
if (angle % 90 !== 0) {
throw new Error("Invalid rotation: must be a multiple of 90");
}
angle %= 360;
if (angle < 0) {
angle += 360;
}
this._rotation = angle;
}
get textColor() {
return this._textColor;
}
set textColor(color) {
if (Color._isValidColor(color)) {
this._textColor = color;
}
}
View on GitHub (pinned to 5903d58d58)