mozilla/pdf.js · error · Error
extractPages: too many pageIndices.
Error message
extractPages: too many pageIndices.
What it means
Plain Error thrown when an image-type pageInfo supplies pageIndices with more than one entry. A single image produces exactly one synthetic page, so multiple target slots are meaningless.
Source
Thrown at src/core/editor/pdf_editor.js:1023
task,
newAnnotationsByPage: getNewAnnotationsMap(annotationStorage),
imagesPromises: AnnotationFactory.generateImages(
annotationStorage.values(),
this.xrefWrapper,
true
),
};
}
const imageEntries = [];
for (const pageInfo of pageInfos) {
const { document, image, includePages, excludePages, pageIndices } =
pageInfo;
if (image) {
if (pageIndices) {
newIndex = -1;
if (pageIndices.length > 1) {
throw new Error("extractPages: too many pageIndices.");
}
}
// Image entries are inserted as synthetic pages. Reserve a slot now;
// the actual page dict is built after real pages are collected so
// that we know the modal MediaBox dimensions to use.
let newPageIndex;
if (pageIndices?.length) {
newPageIndex = pageIndices[0];
} else if (newIndex !== -1) {
newPageIndex = newIndex++;
} else {
for (
newPageIndex = 0;
this.oldPages[newPageIndex] !== undefined;
newPageIndex++
) {
/* empty */
}View on GitHub (pinned to 5903d58d58)
Solutions
- For image pageInfos, omit pageIndices (auto-assign) or supply exactly one index.
- Validate that image entries have pageIndices.length <= 1 before calling extractPages.
- If you need the image at a specific slot, pass pageIndices: [targetSlot].
Example fix
// before
pageInfos = [{ image: myBitmap, pageIndices: [3, 4] }];
// after
pageInfos = [{ image: myBitmap, pageIndices: [3] }];
// or auto-assign:
pageInfos = [{ image: myBitmap }]; Defensive patterns
Strategy: validation
Validate before calling
for (const p of pageInfos) {
if (p.image && p.pageIndices && p.pageIndices.length > 1) {
throw new Error('Image pageInfos may have at most one pageIndex.');
}
} Try / catch
try {
await editor.extractPages(pageInfos, ...);
} catch (e) {
if (e.message === 'extractPages: too many pageIndices.') {
pageInfos = pageInfos.map(p => p.image ? { ...p, pageIndices: p.pageIndices?.slice(0, 1) } : p);
return editor.extractPages(pageInfos, ...);
}
throw e;
} Prevention
- Build pageInfos from typed helpers that constrain image entries to a single slot.
- Validate image pageInfos separately from document pageInfos.
- Prefer omitting pageIndices for image entries to let pdf.js auto-assign.
When it happens
Trigger: Passing { image, pageIndices: [3, 4] } to extractPages—two slots for one image.
Common situations: Caller builds pageInfos generically from a list and accidentally attaches multi-element pageIndices to image entries.
Related errors
- extractPages: partial pageIndices cannot be combined with in
- extractPages: invalid page index.
- extractPages: overlapping pageIndices.
- extractPages: nothing to extract.
- extractPages: sparse pageIndices.
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/3a5d7d843b93d1f8.
Report an issue: GitHub.