siyuan-note/siyuan · error · Error
PDF page view is unavailable
Error message
PDF page view ${pageNumber} is unavailable What it means
getRectImgData looks up the PDF.js page view for the given page number before capturing a rectangle annotation screenshot. If `pdfViewer.getPageView(pageNumber - 1)` returns falsy, it throws "PDF page view ${pageNumber} is unavailable". This means the page is not currently rendered in the viewer's internal page list.
Solutions
- Wait for the PDF document and target page to finish rendering before annotating
- Verify the page number is within 1..pdfDocument.numPages
- Reopen the asset and retry the annotation
- Update pdf.js; newer versions manage page views more robustly
Example fix
// before
const pageView = pdfObj.pdfViewer.getPageView(pageNumber - 1);
if (!pageView) {
throw new Error(`PDF page view ${pageNumber} is unavailable`);
}
// after: guard with page count
const pageCount = pdfObj.pdfDocument ? (await pdfObj.pdfDocument).numPages : pdfObj.pdfViewer.pagesCount;
if (pageNumber < 1 || pageNumber > pageCount || !pdfObj.pdfViewer.getPageView(pageNumber - 1)) {
throw new Error(`PDF page view ${pageNumber} is unavailable`);
} Defensive patterns
Strategy: validation
Validate before calling
const pageCount = pdfObj.pdfViewer.pagesCount;
if (!(pageNumber >= 1 && pageNumber <= pageCount)) { throw new Error(`Page ${pageNumber} out of range`); } Type guard
const pageViewExists = (pdfObj: any, pageNumber: number): boolean => !!pdfObj?.pdfViewer?.getPageView(pageNumber - 1);
Try / catch
try {
await getRectImgData(pdfObj, pageNumber, position);
} catch (e) {
showMessage(e.message); // ask the user to wait for the page to render and retry
} Prevention
- Only start annotation gestures after the target page has rendered
- Clamp page numbers to the document page count
- Guard against document reloads mid-annotation
When it happens
Trigger: Annotating a PDF page whose pageView has not been created — e.g. the page index exceeds the rendered page count, the PDF document is not fully loaded, or the viewer was destroyed/reset while an annotation gesture was in flight.
Common situations: Double-clicking to finish a rectangle annotation right as the document reloads; programmatically driving annotations for pages outside the rendered range; virtualized viewers that only keep nearby pages in memory.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- invalid annotation file
- PDF rectangle annotation has invalid coordinates
- invalid file annotation reference
- missing or invalid annotation
- resolve file annotation asset
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/1fc797b81f3bb101.
Report an issue: GitHub.
Appendix: source
Thrown at app/src/asset/anno.ts:1102
if (path && await canCopy()) {
writeText(`<<${idPath} "${content}">>
{: 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 9f775e8a12)