mozilla/pdf.js · error · Error
GetPageIndex: page has been removed.
Error message
GetPageIndex: page has been removed.
What it means
Thrown by PDFDocumentProxy.getPageIndex(ref) after the worker resolves the cross-reference index but pagesMapper.getPageNumber maps that index to 0. A 0 result means the page exists in the PDF structure tree but is not part of the currently active page set — i.e., it was deleted or excluded by an incremental update or by a page tree reorganization.
Source
Thrown at src/display/api.js:3067
);
this.#pageCache.set(pageIndex, page);
return page;
});
this.#pagePromises.set(pageIndex, promise);
return promise;
}
async getPageIndex(ref) {
if (!isRefProxy(ref)) {
throw new Error("Invalid pageIndex request.");
}
const index = await this.messageHandler.sendWithPromise("GetPageIndex", {
num: ref.num,
gen: ref.gen,
});
const pageNumber = this.pagesMapper.getPageNumber(index + 1);
if (pageNumber === 0) {
throw new Error("GetPageIndex: page has been removed.");
}
return pageNumber - 1;
}
getAnnotations(pageIndex, intent) {
return this.messageHandler.sendWithPromise("GetAnnotations", {
pageIndex: this.pagesMapper.getPageId(pageIndex + 1) - 1,
intent,
});
}
getFieldObjects() {
return this.#cacheSimpleMethod("GetFieldObjects");
}
getSignatures() {
return this.#cacheSimpleMethod("GetSignatures");
}View on GitHub (pinned to 5903d58d58)
Solutions
- Treat this as a soft error: catch and skip the destination, falling back to the next valid page.
- Validate the destination is still reachable via pdfDocument.getPage(pageNumber) before resolving child refs.
- Regenerate or repair the PDF (e.g., re-save via a PDF optimizer) to prune stale refs.
Example fix
// before
const idx = await pdfDocument.getPageIndex(ref);
// after
try {
const idx = await pdfDocument.getPageIndex(ref);
await pdfDocument.getPage(idx + 1);
} catch (e) {
if (e.message === 'GetPageIndex: page has been removed.') {
// destination is stale; skip or default to page 1
} else throw e;
} Defensive patterns
Strategy: try-catch
Validate before calling
const idx = await pdf.getPageIndex(ref).catch(e => {
if (e.message === 'GetPageIndex: page has been removed.') return -1;
throw e;
});
if (idx < 0) { /* stale destination */ } Type guard
null
Try / catch
try {
return await pdf.getPageIndex(ref);
} catch (e) {
if (e.message === 'GetPageIndex: page has been removed.') return null;
throw e;
} Prevention
- Treat outline/named destinations as untrusted — they may point at removed pages.
- After resolving a ref once, cache the result so stale refs are not re-resolved repeatedly.
- Validate the destination page with getPage before navigating.
When it happens
Trigger: Resolving a ref that points to a page node removed via a later PDF revision; using a ref cached from an older copy of the document after it was reloaded; documents whose /Pages /Count or /Kids exclude nodes the ref points to.
Common situations: Incrementally updated PDFs that delete pages but leave dangling references in outlines/named destinations; annotated PDFs re-saved by tools that rewrite the page tree; opening a PDF whose /Pages tree is inconsistent with its /Count.
Related errors
- Catalog object is not a dictionary.
- Invalid top-level pages dictionary.
- Page count in top-level pages dictionary is not an integer.
- PageLabel is not a dictionary.
- Invalid type in PageLabel dictionary.
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/0fed2ae7739b059a.
Report an issue: GitHub.