Stirling-Tools/Stirling-PDF · error · Error
One or both documents have no pages.
Error message
One or both documents have no pages.
What it means
Thrown in the compare handler when Math.max(basePages, compPages) === 0, i.e. both PDFs report zero pages. pdfjs loaded both documents (no password error) but found no renderable pages. This rejects the comparison because there is nothing to compare; a page-count mismatch alone only produces a warning, but zero-on-both is fatal.
Source
Thrown at frontend/editor/src/core/workers/pixelCompareWorker.ts:439
getDocument(loaderOpts(baseBuffer)).promise,
getDocument(loaderOpts(comparisonBuffer)).promise,
]);
const basePages = baseDoc.numPages;
const compPages = compDoc.numPages;
const sharedPages = Math.min(basePages, compPages);
if (basePages !== compPages) {
warnings.push(
formatWarning(warningTemplates.pageCountMismatch, {
base: basePages,
comparison: compPages,
shared: sharedPages,
}),
);
}
if (Math.max(basePages, compPages) === 0) {
throw new Error(warningTemplates.noPages);
}
// Walk every page in the longer document. Pages past the shorter document's length
// are processed one-sided: the missing side is rendered blank and the whole present
// side is treated as a diff.
const totalPages = Math.max(basePages, compPages);
const pageNumbers = Array.from({ length: totalPages }, (_, i) => i + 1);
const hwThreads = self.navigator?.hardwareConcurrency ?? 4;
const defaultConcurrency = Math.max(2, Math.min(8, hwThreads - 1));
const poolSize = Math.max(
1,
Math.min(concurrency ?? defaultConcurrency, totalPages),
);
let totalDiffPixels = 0;
let totalPixelsCount = 0;
let pagesWithChanges = 0;
View on GitHub (pinned to 9ef20dcab8)
Solutions
- Validate each file's page count (numPages > 0) before queuing the comparison.
- Reject empty/corrupt PDFs at upload with a clear message instead of starting the worker.
- Confirm MIME type is application/pdf and that pdfjs reports a positive numPages.
- If only one PDF is empty, treat the comparison as fully-different rather than failing.
Example fix
// before
if (Math.max(basePages, compPages) === 0) {
throw new Error(warningTemplates.noPages);
}
// after
if (basePages === 0 && compPages === 0) {
throw new Error("Both documents have no pages. Select valid PDFs containing at least one page.");
}
if (Math.max(basePages, compPages) === 0) {
throw new Error(warningTemplates.noPages);
} Defensive patterns
Strategy: validation
Validate before calling
function hasPages(doc: PDFDocumentProxy): boolean {
return typeof doc.numPages === "number" && doc.numPages > 0;
}
if (!hasPages(baseDoc) && !hasPages(compDoc)) {
throw new Error("Both documents have no pages. Select PDFs with at least one page.");
} Type guard
const hasPages = (doc: PDFDocumentProxy | null): doc is PDFDocumentProxy => !!doc && typeof doc.numPages === "number" && doc.numPages > 0;
Prevention
- Validate numPages > 0 for each PDF before queuing the comparison.
- Reject empty/corrupt PDFs at upload with a clear message.
- Confirm the file is application/pdf and pdfjs reports a positive numPages.
When it happens
Trigger: Both inputs are valid PDF files with empty page trees (e.g. a PDF container with no pages); corrupt PDFs that parse but expose numPages=0; a non-PDF file mislabeled and partially parsed to 0 pages.
Common situations: User selects placeholder/empty PDFs; a generator emitted a valid header but no page objects; one of the inputs is actually an image or other format that pdfjs loaded as 0 pages.
Related errors
- File ${file.name} appears to be corrupted
- Unexpected trailing input
- Invalid scale ratio: ${ratio}
- Invalid real-world distance (must be positive)
- No team resolved yet
AI-assisted analysis of Stirling-Tools/Stirling-PDF@9ef20dcab8 (2026-08-13).
Data as JSON: /api/errors/93376b112d27b3c4.
Report an issue: GitHub.