siyuan-note/siyuan · error · Error

PDF page view ${pageNumber} is unavailable

Error message

PDF page view ${pageNumber} is unavailable

What it means

Thrown by getRectImgData in the PDF annotation code when pdfObj.pdfViewer.getPageView(pageNumber - 1) returns a falsy page view. The requested page is not currently rendered by the PDF viewer (page number out of range, or the page view was destroyed/not yet created at capture time), so the rectangle annotation screenshot cannot be taken.

Source

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

                        if (path) {
                            writeText(`<<${idPath} "${content}">>
![](${path}){: style="width: ${imageData.displayWidth}px;"}`);
                        }
                    });
                });
            }).catch((error) => {
                console.error(error);
            });
        } else {
            writeText(`<<${idPath} "${content}">>`);
        }
    }, 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,

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Verify pageNumber is within the document's page count and 1-based before calling getRectImgData
  2. Only capture after the page has rendered; wait for pagesetup/pagerendered events
  3. Re-open the PDF asset so the viewer recreates the page views
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at app/src/asset/anno.ts:1085 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/1fc797b81f3bb101. Report an issue: GitHub.