mozilla/pdf.js · error · Error

extractPages: nothing to extract.

Error message

extractPages: nothing to extract.

What it means

Plain Error thrown after collection completes if this.oldPages is empty (length 0). It means no source page or image actually contributed to the new document, so there is nothing to write out.

Source

Thrown at src/core/editor/pdf_editor.js:1096

              newPageIndex = 0;
              this.oldPages[newPageIndex] !== undefined;
              newPageIndex++
            ) {
              /* empty */
            }
          }
        }
        reservePageSlot(newPageIndex);
        promises.push(
          document.getPage(i).then(page => {
            this.oldPages[newPageIndex] = new PageData(page, documentData);
          })
        );
      }
    }
    await Promise.all(promises);
    if (this.oldPages.length === 0) {
      throw new Error("extractPages: nothing to extract.");
    }
    const copyCounts = new Map();
    const documents = new Set();
    for (let i = 0, ii = this.oldPages.length; i < ii; i++) {
      const pageData = this.oldPages[i];
      if (pageData === undefined) {
        throw new Error("extractPages: sparse pageIndices.");
      }
      if (pageData) {
        const { page } = pageData;
        const copyLevel = copyCounts.get(page) ?? 0;
        copyCounts.set(page, copyLevel + 1);
        pageData.copyLevel = copyLevel;
        documents.add(pageData.documentData.document);
      }
    }
    this.isSingleFile = documents.size === 1;
    promises.length = 0;

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Validate that at least one pageInfo has a document/image and that filtering yields >= 1 page before calling extractPages.
  2. Guard upstream: skip the extractPages call entirely when the result would be empty.
  3. Show a user-facing 'nothing to extract' message rather than crashing.

Example fix

// before
await editor.extractPages([], null, primaryDoc, handler, task);

// after
const hasContent = pageInfos.some(p => p.document || p.image);
if (!hasContent) throw new Error('No pages or images selected.');
await editor.extractPages(pageInfos, null, primaryDoc, handler, task);
Defensive patterns

Strategy: validation

Validate before calling

const hasContent = pageInfos.some(p => p.document || p.image);
if (!hasContent) throw new Error('Nothing to extract: no document or image provided.');

Try / catch

try {
  await editor.extractPages(pageInfos, ...);
} catch (e) {
  if (e.message === 'extractPages: nothing to extract.') {
    notifyUser('Select at least one page or image to extract.');
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling extractPages with pageInfos where every entry has no document and no image; all document entries have includePages/excludePages that filter out every page; passing an empty pageInfos array.

Common situations: Caller builds pageInfos dynamically and the source list ends up empty; an empty document is passed (numPages=0) and no pages survive filtering.

Related errors


AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13). Data as JSON: /api/errors/de5575b2875dec66. Report an issue: GitHub.