siyuan-note/siyuan · error · Error

PDF rectangle annotation has invalid coordinates

Error message

PDF rectangle annotation has invalid coordinates

What it means

When capturing a PDF rectangle annotation, the code converts the annotation's position to viewport coordinates and computes a capture scale via getLimitedCaptureScale. If that scale is <= 0, the rectangle has degenerate dimensions and "PDF rectangle annotation has invalid coordinates" is thrown rather than producing a zero-size canvas.

Solutions

  1. Delete and redraw the problematic rectangle annotation
  2. Validate that the annotation drag produced a non-degenerate rectangle before saving
  3. Check for version skew between the annotation data and the current pdf.js viewport code; re-render the document
  4. Verify the page rotation handling by reopening the asset

Example fix

// before
if (captureScale <= 0) {
    throw new Error("PDF rectangle annotation has invalid coordinates");
}
// after: clamp defensively where the rect is created
const [x1, y1, x2, y2] = targetRect;
if (Math.abs(x2 - x1) < 1 || Math.abs(y2 - y1) < 1) {
    return null; // ignore degenerate rectangles instead of throwing
}
Defensive patterns

Strategy: validation

Validate before calling

const [x1, y1, x2, y2] = position;
const valid = Math.abs(x2 - x1) >= 1 && Math.abs(y2 - y1) >= 1;

Type guard

const isFiniteRect = (position: number[]): boolean => Array.isArray(position) && position.length === 4 && position.every(Number.isFinite);

Try / catch

try {
    await captureRectangle(pdfObj, pageNumber, position);
} catch (e) {
    showMessage(e.message); // prompt the user to redraw the rectangle
}

Prevention

When it happens

Trigger: The stored annotation rectangle has zero or negative width/height (degenerate drag), or `position` is malformed/stale relative to the current page viewport/rotation.

Common situations: Annotations created by older app versions with a different coordinate convention; clicking instead of dragging to create a rectangle; position data corrupted by manual .sy editing or sync conflicts.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/c59e93b551e06cd5. Report an issue: GitHub.

Appendix: source

Thrown at app/src/asset/anno.ts:1114

    }, Constants.TIMEOUT_DBLCLICK);
};

async function getRectImgData(pdfObj: any, pageNumber: number, position: number[]) {
    const pageView = pdfObj.pdfViewer.getPageView(pageNumber - 1);
    if (!pageView) {
        throw new Error(`PDF page view ${pageNumber} is unavailable`);
    }

    const pdfPage = await pdfObj.pdfDocument.getPage(pageNumber);
    const totalRotation = ((pageView.rotation + pageView.pdfPageRotate) % 360 + 360) % 360;
    const targetViewport = pdfPage.getViewport({
        scale: PDF_RECT_CAPTURE_SCALE,
        rotation: totalRotation,
    });
    const targetRect = targetViewport.convertToViewportRectangle(position);
    const captureScale = getLimitedCaptureScale(targetRect);
    if (captureScale <= 0) {
        throw new Error("PDF rectangle annotation has invalid coordinates");
    }

    const viewport = pdfPage.getViewport({scale: captureScale, rotation: totalRotation});
    const captureBounds = getCaptureCanvasBounds(viewport.convertToViewportRectangle(position));
    const captureViewport = pdfPage.getViewport({
        scale: captureScale,
        rotation: totalRotation,
        offsetX: -captureBounds.left,
        offsetY: -captureBounds.top,
    });
    const captureCanvas = document.createElement("canvas");
    captureCanvas.width = captureBounds.width;
    captureCanvas.height = captureBounds.height;

    const captureCtx = captureCanvas.getContext("2d");
    if (!captureCtx) {
        throw new Error("Unable to create a canvas context for the PDF rectangle annotation");
    }

View on GitHub (pinned to 9f775e8a12)