Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > Kobo Reader > Kobo Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 09-05-2023, 03:35 PM   #1
chris33
Enthusiast
chris33 began at the beginning.
 
Posts: 34
Karma: 10
Join Date: Sep 2020
Device: ipad, kobo libra 2
Lightbulb Get number of pages of a book in sqlite DB

Hi,
I need to retrieve the number of pages of some books from the KoboReader.sqlite database file.

It looks like content/___NumPages might show the information but for pdf only. It doesn’t seem to give any information for epub/mobi files for instance.

Do you know a way of getting a book’s number of pages for any format ?

chris33 is offline   Reply With Quote
Old 09-06-2023, 02:50 AM   #2
Szybet
Connoisseur
Szybet can teach chickens to fly.Szybet can teach chickens to fly.Szybet can teach chickens to fly.Szybet can teach chickens to fly.Szybet can teach chickens to fly.Szybet can teach chickens to fly.Szybet can teach chickens to fly.Szybet can teach chickens to fly.Szybet can teach chickens to fly.Szybet can teach chickens to fly.Szybet can teach chickens to fly.
 
Posts: 86
Karma: 3892
Join Date: Feb 2022
Device: Kobo nia
Epub's don't have a fixed number of pages, it depends on font, margins etc. Kobo may save this value somewhere to not calculate it every time, or just don't ¯\_(ツ)_/¯
Szybet is offline   Reply With Quote
Advert
Old 09-06-2023, 04:03 AM   #3
Aleron Ives
Wizard
Aleron Ives ought to be getting tired of karma fortunes by now.Aleron Ives ought to be getting tired of karma fortunes by now.Aleron Ives ought to be getting tired of karma fortunes by now.Aleron Ives ought to be getting tired of karma fortunes by now.Aleron Ives ought to be getting tired of karma fortunes by now.Aleron Ives ought to be getting tired of karma fortunes by now.Aleron Ives ought to be getting tired of karma fortunes by now.Aleron Ives ought to be getting tired of karma fortunes by now.Aleron Ives ought to be getting tired of karma fortunes by now.Aleron Ives ought to be getting tired of karma fortunes by now.Aleron Ives ought to be getting tired of karma fortunes by now.
 
Posts: 1,014
Karma: 11500112
Join Date: Sep 2022
Device: Kobo Libra 2
There is no such value. The whole point of EPUB is that the page layout is variable, depending upon your chosen font face, font size, margins, and line spacing.

The closest you can get is to count the number of words or characters and then divide by a fixed number of words or characters per page to get an approximation of the number of pages a paper book would have, but you have to choose the divisor arbitrarily, since different font sizes and page sizes yield different words per page in paper books.
Aleron Ives is offline   Reply With Quote
Old 09-06-2023, 04:46 AM   #4
qkqw
Connoisseur
qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.qkqw is at one with the great books of the world.
 
Posts: 58
Karma: 143000
Join Date: Apr 2022
Device: Kobo Libra 2
I've looked at this when working on https://www.mobileread.com/forums/sh...d.php?t=349637

As you said, for PDFs you can easily get the current page number. For Epubs the best you can do is a percentage read (___PercentRead) and the current chapter (Title).
qkqw is offline   Reply With Quote
Old 09-06-2023, 03:41 PM   #5
chris33
Enthusiast
chris33 began at the beginning.
 
Posts: 34
Karma: 10
Join Date: Sep 2020
Device: ipad, kobo libra 2
ah ok I didn't know that.
Is this the same with mobi files ?
chris33 is offline   Reply With Quote
Advert
Old 09-06-2023, 09:21 PM   #6
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 35,340
Karma: 145435140
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Forma, Clara HD, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Quote:
Originally Posted by chris33 View Post
ah ok I didn't know that.
Is this the same with mobi files ?
Yes. It will be the same for any reflowable format since margins, line spacing, line height, font size will all affect the amount of text that will fit on a page.

If you do a search on MobileRead, you will find pages of discussions about why there is no one true page count for epubs and other reflowable books. An example for Google would be 'epub page numbering site:mobileread.com' (remove the quotes). They tend to get repetitive but are good for when insomnia strikes. Nothing like reading about the ONE TRUE PAGE NUMBERING heresy to cause me to want a nap.
DNSB is offline   Reply With Quote
Old 09-07-2023, 08:09 AM   #7
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 73,931
Karma: 128903250
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
ADE page numbering is the one true page number for ePub.

Code:
One page number to rule them all,
   one page number to find them,
One page number to bring them all
   and in the darkness bind them.

Last edited by JSWolf; 09-07-2023 at 08:11 AM.
JSWolf is offline   Reply With Quote
Old 09-07-2023, 12:33 PM   #8
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 35,340
Karma: 145435140
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Forma, Clara HD, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Quote:
Originally Posted by JSWolf View Post
ADE page numbering is the one true page number for ePub.
Page-map and pagelist both give consistent page numbers across devices since they depend on a pre-built page number list generally based on a hard cover paperbook edition. One issue is that a page number can occur anywhere on the screen. At one point, calibre supported page-map in ePubs but that disappeared in 2009-2010 (going by my vague recollection).

There were other ePub synthetic page numbering schemes that worked or could work across devices. The key is that both the alternatives to the Adobe algorithm I am aware of mimic the Adobe SPN and calculate the pages in the ePub based on the number of synthetic pages in each text file and have no relationship to the pages seen when reading so a page number can occur anywhere on the screen.

For all of them, the base algorithm is similar to the one use by Adobe's algorithm:
  • Determine a compressed byte length of each resource which is referenced in the spine, subtracting any known encryption overhead (IV size).
  • Assume that there is a page for each 1024 bytes in each resource, rounding up to the nearest whole number of pages for each resource.
  • To map page breaks into a resource, use the number of pages for the resource as determined in step 2, count the number of Unicode characters in the resource; distribute synthetic page breaks in the resource evenly between the characters by dividing the number of characters by the number of pages; if the number of characters don’t divide evenly among the pages, round the number of characters per page up and let the last “page” contain less characters than the rest.

The other two differed in the number of compressed characters per page (1000 and 1023), the allowance for encryption and compression overhead and for one of them, the ability to recognize images and B64 inline images. That one required unencrypted ePubs to work properly and was slower than molasses since it had to unzip each text file but it could also add a page-map file and page numbers internal to the ePub which looks something like <a id="Page_023"/> going off my rather vague recollection. Both those projects have long since passed into abandonware.
DNSB is offline   Reply With Quote
Old 09-07-2023, 04:06 PM   #9
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 73,931
Karma: 128903250
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Is there any easy way to make a page map that works with RMSDK if you have page number IDs in the ePub?
JSWolf is offline   Reply With Quote
Old 09-07-2023, 05:19 PM   #10
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 35,340
Karma: 145435140
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Forma, Clara HD, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Quote:
Originally Posted by JSWolf View Post
Is there any easy way to make a page map that works with RMSDK if you have page number IDs in the ePub?
It should be fairly easy to do automatically if someone wrote a tool but I'm not aware of any existing tools. Checking the few epubs I have around that have page numbers as IDs, they also have pageList entries in the XHTML navigation document and toc.ncx files. Since pageList is a part of the epub recommendation and that 15 years ago, the comment on page-map was "the 'page-map' attribute is not supported in the OPF Package Schema and thus NOT ALLOWED.", implementing page-map is unlikely to be a good idea.

Oddly the epubs that I have the implement pageList tend to flag that portion of the XHTML navigation document as hidden.

Code:
<nav epub:type="page-list" hidden="hidden">
 <ol>
   <li><a href="hurkle.xhtml#page101">101</a></li>
   <li><a href="hurkle.xhtml#page102">102</a></li>
   <li><a href="hurkle.xhtml#page103">103</a></li>
   <li><a href="hurkle.xhtml#page104">104</a></li>
 </ol>
</nav>
DNSB is offline   Reply With Quote
Old 09-08-2023, 01:54 AM   #11
chris33
Enthusiast
chris33 began at the beginning.
 
Posts: 34
Karma: 10
Join Date: Sep 2020
Device: ipad, kobo libra 2
ok thank you for the explanations, I'll stick to a percentage+chapter name for locating highlights on my kobo books.
chris33 is offline   Reply With Quote
Reply

Tags
database, kobo, sqlite3


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
The viewer's calculation of number of pages in a book? John IV Viewer 2 06-04-2023 03:58 PM
Number of pages in a book albare Kobo Reader 14 01-28-2022 09:42 PM
Show number of pages in book - where? manawydan Viewer 2 08-06-2020 12:43 PM
Create column to show number of pages in book Teeg Calibre 3 05-03-2018 07:44 PM
Do the number of pages in an ebook differ from the number of pages in a physical book Phoebemy General Discussions 12 07-19-2012 09:25 AM


All times are GMT -4. The time now is 08:17 PM.


MobileRead.com is a privately owned, operated and funded community.