{"record":{"id":"3a5d7d843b93d1f8","repo":"mozilla/pdf.js","slug":"extractpages-too-many-pageindices","errorCode":null,"errorMessage":"extractPages: too many pageIndices.","messagePattern":"extractPages: too many pageIndices\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/core/editor/pdf_editor.js","lineNumber":1023,"sourceCode":"        task,\n        newAnnotationsByPage: getNewAnnotationsMap(annotationStorage),\n        imagesPromises: AnnotationFactory.generateImages(\n          annotationStorage.values(),\n          this.xrefWrapper,\n          true\n        ),\n      };\n    }\n\n    const imageEntries = [];\n    for (const pageInfo of pageInfos) {\n      const { document, image, includePages, excludePages, pageIndices } =\n        pageInfo;\n      if (image) {\n        if (pageIndices) {\n          newIndex = -1;\n          if (pageIndices.length > 1) {\n            throw new Error(\"extractPages: too many pageIndices.\");\n          }\n        }\n        // Image entries are inserted as synthetic pages. Reserve a slot now;\n        // the actual page dict is built after real pages are collected so\n        // that we know the modal MediaBox dimensions to use.\n        let newPageIndex;\n        if (pageIndices?.length) {\n          newPageIndex = pageIndices[0];\n        } else if (newIndex !== -1) {\n          newPageIndex = newIndex++;\n        } else {\n          for (\n            newPageIndex = 0;\n            this.oldPages[newPageIndex] !== undefined;\n            newPageIndex++\n          ) {\n            /* empty */\n          }","sourceCodeStart":1005,"sourceCodeEnd":1041,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/editor/pdf_editor.js#L1005-L1041","documentation":"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.","triggerScenarios":"Passing { image, pageIndices: [3, 4] } to extractPages—two slots for one image.","commonSituations":"Caller builds pageInfos generically from a list and accidentally attaches multi-element pageIndices to image entries.","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]."],"exampleFix":"// before\npageInfos = [{ image: myBitmap, pageIndices: [3, 4] }];\n\n// after\npageInfos = [{ image: myBitmap, pageIndices: [3] }];\n// or auto-assign:\npageInfos = [{ image: myBitmap }];","handlingStrategy":"validation","validationCode":"for (const p of pageInfos) {\n  if (p.image && p.pageIndices && p.pageIndices.length > 1) {\n    throw new Error('Image pageInfos may have at most one pageIndex.');\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await editor.extractPages(pageInfos, ...);\n} catch (e) {\n  if (e.message === 'extractPages: too many pageIndices.') {\n    pageInfos = pageInfos.map(p => p.image ? { ...p, pageIndices: p.pageIndices?.slice(0, 1) } : p);\n    return editor.extractPages(pageInfos, ...);\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["editor","extract-pages","image","validation"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}