{"record":{"id":"c59e93b551e06cd5","repo":"siyuan-note/siyuan","slug":"pdf-rectangle-annotation-has-invalid-coordinates","errorCode":null,"errorMessage":"PDF rectangle annotation has invalid coordinates","messagePattern":"PDF rectangle annotation has invalid coordinates","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"app/src/asset/anno.ts","lineNumber":1097,"sourceCode":"    }, Constants.TIMEOUT_DBLCLICK);\n};\n\nasync function getRectImgData(pdfObj: any, pageNumber: number, position: number[]) {\n    const pageView = pdfObj.pdfViewer.getPageView(pageNumber - 1);\n    if (!pageView) {\n        throw new Error(`PDF page view ${pageNumber} is unavailable`);\n    }\n\n    const pdfPage = await pdfObj.pdfDocument.getPage(pageNumber);\n    const totalRotation = ((pageView.rotation + pageView.pdfPageRotate) % 360 + 360) % 360;\n    const targetViewport = pdfPage.getViewport({\n        scale: PDF_RECT_CAPTURE_SCALE,\n        rotation: totalRotation,\n    });\n    const targetRect = targetViewport.convertToViewportRectangle(position);\n    const captureScale = getLimitedCaptureScale(targetRect);\n    if (captureScale <= 0) {\n        throw new Error(\"PDF rectangle annotation has invalid coordinates\");\n    }\n\n    const viewport = pdfPage.getViewport({scale: captureScale, rotation: totalRotation});\n    const captureBounds = getCaptureCanvasBounds(viewport.convertToViewportRectangle(position));\n    const captureViewport = pdfPage.getViewport({\n        scale: captureScale,\n        rotation: totalRotation,\n        offsetX: -captureBounds.left,\n        offsetY: -captureBounds.top,\n    });\n    const captureCanvas = document.createElement(\"canvas\");\n    captureCanvas.width = captureBounds.width;\n    captureCanvas.height = captureBounds.height;\n\n    const captureCtx = captureCanvas.getContext(\"2d\");\n    if (!captureCtx) {\n        throw new Error(\"Unable to create a canvas context for the PDF rectangle annotation\");\n    }","sourceCodeStart":1079,"sourceCodeEnd":1115,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/app/src/asset/anno.ts#L1079-L1115","documentation":"Guard in getRectImgData rejecting an annotation rectangle whose coordinates are not usable for capture (empty, inverted, or non-finite position values passed in the position array). The PDF rectangle annotation cannot be rendered to an image from such coordinates.","triggerScenarios":"Thrown at app/src/asset/anno.ts:1097 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Validate the selection rectangle has width and height greater than 0 before capture","Clamp coordinates to the page viewport bounds","Discard zero-area or inverted drag selections in the annotation UI"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}