{"record":{"id":"8652fd749eff5bf5","repo":"mozilla/pdf.js","slug":"pageviewport-invalid-rotation-must-be-a-multiple","errorCode":null,"errorMessage":"PageViewport: Invalid rotation, must be a multiple of 90 degrees.","messagePattern":"PageViewport: Invalid rotation, must be a multiple of 90 degrees\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/display/page_viewport.js","lineNumber":108,"sourceCode":"        rotateA = 0;\n        rotateB = 1;\n        rotateC = 1;\n        rotateD = 0;\n        break;\n      case 270:\n        rotateA = 0;\n        rotateB = -1;\n        rotateC = -1;\n        rotateD = 0;\n        break;\n      case 0:\n        rotateA = 1;\n        rotateB = 0;\n        rotateC = 0;\n        rotateD = -1;\n        break;\n      default:\n        throw new Error(\n          \"PageViewport: Invalid rotation, must be a multiple of 90 degrees.\"\n        );\n    }\n\n    if (dontFlip) {\n      rotateC = -rotateC;\n      rotateD = -rotateD;\n    }\n\n    let offsetCanvasX, offsetCanvasY;\n    let width, height;\n    if (rotateA === 0) {\n      offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;\n      offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;\n      width = (viewBox[3] - viewBox[1]) * scale;\n      height = (viewBox[2] - viewBox[0]) * scale;\n    } else {\n      offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/display/page_viewport.js#L90-L126","documentation":"Thrown by the PageViewport constructor when, after normalizing rotation into [0,360), the value is not 0, 90, 180, or 270. PageViewport builds a coordinate transform with an explicit case per valid quadrant, so any non-orthogonal angle cannot be represented and is rejected. This is a caller-input error, not a PDF-content error.","triggerScenarios":"new PageViewport({ viewBox, scale, rotation }) is called with rotation not a multiple of 90 (e.g. 45, 12.5, radians).","commonSituations":"Passing radians instead of degrees; passing a fractional rotation; computing rotation from a free-form angle control; misusing a value pulled from page.rotate after mutating it.","solutions":["Pass only one of 0, 90, 180, 270 for rotation.","Use page.rotate (already a valid multiple of 90) rather than computing your own angle.","Clamp/snap a user angle to the nearest multiple of 90 before constructing the viewport.","Validate rotation with a modulo-90 check before constructing the viewport."],"exampleFix":"// before\nconst viewport = new PageViewport({ viewBox, scale, rotation: 45 });\n// after\nconst viewport = new PageViewport({ viewBox, scale, rotation: 90 });","handlingStrategy":"validation","validationCode":"function normalizeRotation(r) {\n  const mod = ((r % 360) + 360) % 360;\n  return mod % 90 === 0 ? mod : null;\n}\nconst rot = normalizeRotation(rotation);\nif (rot === null) throw new Error('rotation must be a multiple of 90');","typeGuard":"function isValidViewportRotation(rotation) {\n  const mod = ((Number(rotation) % 360) + 360) % 360;\n  return mod === 0 || mod === 90 || mod === 180 || mod === 270;\n}","tryCatchPattern":null,"preventionTips":["Always source rotation from page.rotate rather than computing it.","Remember PDF rotation is in degrees, not radians.","Snap any user-facing angle control to multiples of 90.","Validate rotation mod 90 before constructing a PageViewport."],"tags":["viewport","rotation","api-misuse","input-validation"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}