Skip to content

Instantly share code, notes, and snippets.

@dmalinovsky
Created April 2, 2024 23:02
Show Gist options
  • Save dmalinovsky/69fd68af7848008b1cc80a76961f2d77 to your computer and use it in GitHub Desktop.
Save dmalinovsky/69fd68af7848008b1cc80a76961f2d77 to your computer and use it in GitHub Desktop.
Patch for KOReader to build logical page count
local ReaderPageMap = require("apps/reader/modules/readerpagemap")
local postInit_orig = ReaderPageMap._postInit
ReaderPageMap._postInit = function(self)
self.ui.document:buildSyntheticPageMapIfNoneDocumentProvided(1818)
-- Run original code
postInit_orig(self)
end
Copy link

ghost commented May 25, 2024

Can you change (add to) this userpatch so that it shows how many pages are left until the end of the book, so that is, it shows: current pages 150/498, then let it show: left pages 348/498 please 🥺 I hope you understood me. I know it's not right something about code and Roman numerals like XIV etc., but I need this to show how much pages left. PLEASE HEAR ME 🙏

@edo-jan
Copy link

edo-jan commented Aug 16, 2024

Hi Denis, can you please help us figuring out what exactly your patch does. This would be most helpful to further improve Kohighlights - a nifty little program that allows users to synchronize highlights and annotations across Koreader instances running on different devices (in my case a Kobo reader, Android phone and WSL desktop instance). The long story short, your patch makes it possible to harmonize the page numbers across all the devices, however when the highlights and annotations are exported to Kohighlights the page numbers are no longer the same. I am in touch with the author of the Kohighlights and he is willing to help. However he needs to understand what exactly your patch is doing and how it makes the calc of the logical page numbers. Without it he won't be able to integrate the logic into his tool which would then make it possible to harmonize the page numbering. Please see here for details. Your input would be much appreciated!

@dmalinovsky
Copy link
Author

My patch is simply calling buildSyntheticPageMapIfNoneDocumentProvided function. It checks if there's no existing page map and then marks a page every N symbols (in my case, 1818).

Here's a corresponding change in crengine: koreader/crengine#478. The author should look there.

@edo-jan
Copy link

edo-jan commented Aug 16, 2024

Thank you Denis!

@NQK
Copy link

NQK commented Mar 27, 2025

I was looking for something like this. My purpose is to see if one book is really longer than another. I use 1024 for no reason.

It's a pity that everyone has to invent their own counting methods.

How about a patch to use the ADE counting method? Why? I'm sure Pocketbook is using it and Calibre has a plugin to count pages using this. Somehow when I enter the 1024 to that plugin it doesn't return the number generated by current patch as shown in Koreader.

@dmalinovsky
Copy link
Author

I looked into it but it’s impossible (read: too tricky) to use from KOReader. ADE is using 1K of the compressed bytes as a single page and KOReader operates on uncompressed data.

@dmalinovsky
Copy link
Author

Here's the relevant comment in the issue: koreader/koreader#9020 (comment)

@NQK
Copy link

NQK commented Mar 29, 2025

Thank you.

So there is no way to automatically fill the calibre database with the reference/logical page, I guess.

@dmalinovsky
Copy link
Author

I think it should be possible to fill in the reference pages in bulk with Calibre. And then KOReader should use them.

@sgrodnik
Copy link

Thank you @dmalinovsky! How did you calculate 1818? I used 2048 as a common value, but I'm curious about your reasoning

@dmalinovsky
Copy link
Author

Thank you @dmalinovsky! How did you calculate 1818? I used 2048 as a common value, but I'm curious about your reasoning

It’s just Russian publishing specific number — 40,000 characters per 22 pages equals 1,818 characters.

@idontknowtocodeanything

How can I find a common value for Brazilian Portuguese publishing specific number? I'm using the default one in this patch. Thanks in advance!

@dmalinovsky
Copy link
Author

How can I find a common value for Brazilian Portuguese publishing specific number? I'm using the default one in this patch. Thanks in advance!

I don’t think you’ll find an exact number. The one I’m using is good enough. Feel free to tweak it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment