epub.js
epub.js copied to clipboard
Total pages and redirect to a specific page
I can´t find a way to get the total pages of a whole epub file, let alone redirect to a specific page. I know that this depends on the epub's chapters and his rendition (with his size letter and others settings) but there should be a way to calculate it.
To get the total number of pages use: this.book.locations.length() This is not exactly pages, this is the number of locations calculated at the beginning (by default every 600 characters). To jump to specific page use this.book.locations.cfiFromLocation(pageNumber) This will return the CFI of the page. To actually jump use: this.display(cfi);
I hope this helps.
-- Ori Idan CEO Helicon Books http://www.heliconbooks.com
On Tue, Feb 22, 2022 at 4:17 PM Aldo @.***> wrote:
I can´t find a way to get the total pages of a whole epub file, let alone redirect to a specific page. I know that this depends on the epub's chapters and his rendition (with his size letter and others settings) but there should be a way to calculate it.
— Reply to this email directly, view it on GitHub https://github.com/futurepress/epub.js/issues/1252, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAB43QHMGOLLKMWMJMTEJILU4OLGXANCNFSM5PBQZP3A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you are subscribed to this thread.Message ID: @.***>
Another way to get total Page
- Hiddenly render every chapter.
- Sum up the value of
rendition.location.start.displayed.total
of each chapter - Total summation is the total page by rendition format.
- Finally destroy hidden Rendition and elements.
@OriIdan this.book.locations.cfiFromLocation(pageNumber) always return -1, what can be the reason?
Make sure you have locations. Locations should be calculated at first opening.
On Sat, Mar 5, 2022 at 5:36 PM Erdogan @.***> wrote:
@OriIdan https://github.com/OriIdan this.book.locations.cfiFromLocation(pageNumber) always return -1, what can be the reason?
— Reply to this email directly, view it on GitHub https://github.com/futurepress/epub.js/issues/1252#issuecomment-1059784359, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAB43QB32STOZPJTHAOVW43U6N5QNANCNFSM5PBQZP3A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you were mentioned.Message ID: @.***>
Use: this.book.locations.generate(600); You should call locations.generate when you open the book, you can also save the result. The result is an array of objects. In this example it will create a "page" every 600 characters. It does not affect the actual paging according to font size and screen size.
On Sat, Mar 5, 2022 at 5:52 PM Erdogan @.***> wrote:
@OriIdan https://github.com/OriIdan thanks for your answer. How can I calculate it at first, could you share a sample, please?
— Reply to this email directly, view it on GitHub https://github.com/futurepress/epub.js/issues/1252#issuecomment-1059786683, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAB43QBOFMZMNCY6XXV7ECDU6N7NLANCNFSM5PBQZP3A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you were mentioned.Message ID: @.***>
@OriIdan yes its returning now! but unfortunately not accurate with loc.start.displayed.page value.
If I enter the page number as 10, it navigated to page 6.
Another way to get total Page
- Hiddenly render every chapter.
- Sum up the value of
rendition.location.start.displayed.total
of each chapter- Total summation is the total page by rendition format.
- Finally destroy hidden Rendition and elements.
This work for me. But it's to slowly.. Any way to get every chapter faster? @RatulSikder97