Kareadita/Kavita · warning · KavitaException
Page {bookmarkDto.Page} not found in epub
Error message
Page {bookmarkDto.Page} not found in epub What it means
Thrown by BookService.CopyImageToTempFromBook (line 1321) after the reading-order loop completes without finding a page matching bookmarkDto.Page (and XHTML_1_1 content type). The requested page index is outside the epub's spine/reading order.
Source
Thrown at Kavita.Services/BookService.cs:1321
_ => ".png"
};
}
// Create temp directory for this chapter if it doesn't exist
var tempChapterDir = Path.Combine(directoryService.TempDirectory, chapterId.ToString());
directoryService.ExistOrCreate(tempChapterDir);
// Generate unique filename
var uniqueFilename = $"{Guid.NewGuid()}{extension}";
var tempFilePath = Path.Combine(tempChapterDir, uniqueFilename);
// Write the image to the temp file
await File.WriteAllBytesAsync(tempFilePath, imageContent, ct);
return tempFilePath;
}
throw new KavitaException($"Page {bookmarkDto.Page} not found in epub");
}
private static string? GetImageSrcAttributeName(HtmlNode targetImage)
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
if (targetImage.Attributes["src"] != null)
{
return "src";
}
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
if (targetImage.Attributes["xlink:href"] != null)
{
return "xlink:href";
}
return null;
}
View on GitHub (pinned to 9c3e540000)
Solutions
- Validate bookmarkDto.Page against the epub's page count (0-based reading order) before calling.
- Refresh book metadata on the client when the epub is re-scanned/replaced.
Example fix
// before
throw new KavitaException($"Page {bookmarkDto.Page} not found in epub");
// caller
if (bookmarkDto.Page < 0 || bookmarkDto.Page >= totalPages) return BadRequest("Invalid page"); Defensive patterns
Strategy: validation
Validate before calling
// Validate page bounds before copy-image (0-based reading order)
if (bookmarkDto.Page < 0 || bookmarkDto.Page >= totalPages)
return BadRequest("Invalid page"); Prevention
- Use zero-based page indexing consistent with the epub reading order.
- Refresh page count when the epub is re-scanned/replaced.
When it happens
Trigger: Bookmark/copy-image request where bookmarkDto.Page is >= the number of XHTML pages in the reading order, or references a non-XHTML page (the loop only matches XHTML_1_1 pages with the right counter).
Common situations: Stale page index from a reader open on an older version of the epub; off-by-one (1-based vs 0-based) between client and the zero-based reading-order counter; page is an image/PDF-style non-XHTML entry.
Related errors
- Image index {bookmarkDto.ImageOffset} is out of range. Page
- No images found on the specified page
- Image element does not have a valid source attribute
- Cannot copy external images
- Image file not found in epub: {imageKey}
AI-assisted analysis of Kareadita/Kavita@9c3e540000 (2026-08-13).
Data as JSON: /api/errors/9a4a1b720fc17ece.
Report an issue: GitHub.